IronPython操作xml
机翻,源自:比邻星
import clr clr.AddReference('System.Xml') from System.Xml import XmlDocument, XmlNode, XmlNodeList, XmlElement class XmlHelper: @staticmethod def AppendChild(filePath, xPath, xmlNode): try: doc = XmlDocument() doc.Load(filePath) xn = doc.SelectSingleNode(xPath) n = doc.ImportNode(xmlNode, True) xn.AppendChild(n) doc.Save(filePath) return True except: return False @staticmethod def AppendChildFromAnotherXml(filePath, xPath, toFilePath, toXPath): try: doc = XmlDocument() doc.Load(toFilePath) xn = doc.SelectSingleNode(toXPath) xnList = XmlHelper.ReadNodes(filePath, xPath) if xnList is not None: for xe in xnList: n = doc.ImportNode(xe, True) xn.AppendChild(n) doc.Save(toFilePath) return True except: return False @staticmethod def UpdateNodeInnerText(filePath, xPath, value): try: doc = XmlDocument() doc.Load(filePath) xn = doc.SelectSingleNode(xPath) xe = xmlNode.Cast(XmlElement) xe.InnerText = value doc.Save(filePath) return True except: return False @staticmethod def LoadXmlDoc(filePath): try: doc = XmlDocument() doc.Load(filePath) return doc except: return None @staticmethod def ReadNodes(filePath, xPath): try: doc = XmlDocument() doc.Load(filePath) xn = doc.SelectSingleNode(xPath) xnList = xn.ChildNodes # Get the node's child nodes return xnList except: return None # 使用示例 # xmlFilePath = 'path_to_your_xml_file.xml' # appended = XmlHelper.AppendChild(xmlFilePath, "Your/Xpath/Here", yourXmlNode) # if appended: # print("Node appended successfully.") # else: # print("Failed to append node.")
IronPython操作xml
机翻,源自:比邻星import clrclr.AddReference('System.Xml')from System.Xml import XmlDocument, XmlNode, XmlNodeList, XmlElementclas...
点击下载文档
本文2024-09-16 18:06:12发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-19962.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
- 鼎捷EAI整合規範文件V3.1.07 (集團).pdf
- 鼎捷OpenAPI應用場景說明_基礎資料.pdf
- 鼎捷OpenAPI應用場景說明_財務管理.pdf
- 鼎捷T100 API設計器使用手冊T100 APIDesigner(V1.0).docx
- 鼎新e-GoB2雲端ERP B2 線上課程E6-2應付票據整批郵寄 領取.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A4使用者建立權限設定.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程C3會計開帳與會計傳票.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程E6-1應付票據.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A5-1進銷存參數設定(初階篇).pdf
- 鼎新e-GoB2雲端ERP B2 線上課程D2帳款開帳與票據開帳.pdf
热门文章