[英]Exclude various nodes from an XML export
我已将 XML 导入 excel 并想从 ZBF57C906FA7D1856D073729 中导出 XML,但排除一些已映射的节点。 这是目前的 XML:
<?xml version="1.0" encoding="UTF-8" standalone="true"?> -<ImportExportRecord xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Version>1.99</Version> <Product>Test Software</Product> -<Employees> -<Employee> <EmployeeID>76</EmployeeID> <Name>John Smith</Name> </Employee> <Employees> -<Job Roles> -<Role> -<Individual> <Skillset>55</Skillset> <Skillset2>854</Skillset2> </Individual> </Role> </Job Roles> -<Attributes> -<Att1> -<Related> <DataInput>98545</DataInput> <DataOutput>874445</DataOutput> </Related> </Att1> </Attributes>
我希望它出口
<?xml version="1.0" encoding="UTF-8" standalone="true"?> -<ImportExportRecord xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Version>1.99</Version> <Product>Test Software</Product> -<Employees> -<Employee> <EmployeeID>76</EmployeeID> <Name>John Smith</Name> </Employee> <Employees> -<Job Roles> -<Role> -<Individual> <Skillset>55</Skillset> </Individual> </Role> </Job Roles>
我目前用来导出 XML 的代码是这样的:
Sub ExportAsXMLData()
Dim objMapToExport As XmlMap
Set objMapToExport = ActiveWorkbook.XmlMaps("ALL")
If objMapToExport.IsExportable Then
ActiveWorkbook.SaveAsXMLData "Employee Data.xml", objMapToExport
Else
MsgBox "Cannot use " & objMapToExport.Name & _
"to export the contents of the worksheet to XML data."
End If
End Sub
任何帮助将不胜感激。
谢谢你。
使用 MSXML2.DOMDocument object 解析文档,然后您可以使用可用方法操作节点。
尝试这样的事情:
Dim xmlObj As MSXML2.DOMDocument
Dim xmlSelector As MSXML2.IXMLDOMSelection
Set xmlObj = CreateObject("MSXML2.DOMDocument")
With xmlObj
.validateOnParse = true
.setProperty "SelectionLanguage", "XPath"
If Not .load(xmlDocPath) Then
(throw error...)
End If
Set xmlSelector = xmlObj.selectNodes("/ImportExportRecord/Attributes") 'take xpath as argument'
xmlSelector.removeAll
.save(saveToFilePath)
End With
您需要检查您引用的库中是否检查了“Microsoft XML,v3.0”库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.