我有一个xml文档,我有xsd文件。现在我想基于excel输入生成xml文件。我在xml文档有多个元素节点时面临的问题。我不知道如何处理这个部分,因为excel Import xml不处理这种类型的结构。
VBA会在这方面提供帮助吗?任何提示/想法都会有所帮助。
XML文档:
<?xml version="1.0"?>
<Sample>
<Sample-List>
<Id>3342</Id>
<Version>3342</Version>
<Name>TypeC</Name>
<Vendor>
<Vendor-Id>xxx</Vendor-Id>
<Vendor-Name>SAM</Vendor-Name>
<Vendor-Type>
<Vendor-Type-Id>AAAA-1</Vendor-Type-Id>
<Vendor-Type-Code>AAAA-2</Vendor-Type-Code>
<Vendor-Type-Mode>Active</Vendor-Type-Mode>
<Vendor-Type-AC-Min>1</Vendor-Type-AC-Min>
<Vendor-Type-AC-Max>4</Vendor-Type-AC-Max>
<Vendor-Type-depends-on>
<EMP-Code>AAAA-3</EMP-Code>
<EMP-Id>AAAA-4</EMP-Id>
<EMP-Name>AAAA-5</EMP-Name>
<EMP-Details>
<Property-Code>AAAA-6</Property-Code>
<Cash-Code>AAAA-7</Cash-Code>
</EMP-Details>
<EMP-Details>
<Property-Code>AAAA-8</Property-Code>
<Cash-Code>AAAA-9</Cash-Code>
</EMP-Details>
</Vendor-Type-depends-on>
</Vendor-Type>
<Vendor-Type>
<Vendor-Type-Id>BBBB-1</Vendor-Type-Id>
<Vendor-Type-Code>BBBB-2</Vendor-Type-Code>
<Vendor-Type-Mode>Active</Vendor-Type-Mode>
<Vendor-Type-AC-Min>1</Vendor-Type-AC-Min>
<Vendor-Type-AC-Max>4</Vendor-Type-AC-Max>
</Vendor-Type>
<Vendor-Type>
<Vendor-Type-Id>CCCC-1</Vendor-Type-Id>
<Vendor-Type-Code>CCCC-2</Vendor-Type-Code>
<Vendor-Type-Mode>Active</Vendor-Type-Mode>
<Vendor-Type-AC-Min>1</Vendor-Type-AC-Min>
<Vendor-Type-AC-Max>4</Vendor-Type-AC-Max>
</Vendor-Type>
<Vendor-Type>
<Vendor-Type-Id>DDDD-1</Vendor-Type-Id>
<Vendor-Type-Code>DDDD-2</Vendor-Type-Code>
<Vendor-Type-Mode>Active</Vendor-Type-Mode>
<Vendor-Type-AC-Min>1</Vendor-Type-AC-Min>
<Vendor-Type-AC-Max>4</Vendor-Type-AC-Max>
<Vendor-Type-depends-on>
<EMP-Code>DDDD-3</EMP-Code>
<EMP-Id>DDDD-4</EMP-Id>
<EMP-Name>DDDD-5</EMP-Name>
<EMP-Details>
<Property-Code>DDDD-6</Property-Code>
<Cash-Code>DDDD-7</Cash-Code>
</EMP-Details>
<EMP-Details>
<Property-Code>DDDD-8</Property-Code>
<Cash-Code>DDDD-9</Cash-Code>
</EMP-Details>
</Vendor-Type-depends-on>
</Vendor-Type>
</Vendor>
XSD文件:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Sample">
<xs:complexType>
<xs:sequence>
<xs:element name="Sample-List">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="Id"/>
<xs:element type="xs:short" name="Version"/>
<xs:element type="xs:string" name="Name"/>
<xs:element name="Vendor">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Vendor-Id"/>
<xs:element type="xs:string" name="Vendor-Name"/>
<xs:element name="Vendor-Type" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Vendor-Type-Id"/>
<xs:element type="xs:string" name="Vendor-Type-Code"/>
<xs:element type="xs:string" name="Vendor-Type-Mode"/>
<xs:element type="xs:byte" name="Vendor-Type-AC-Min"/>
<xs:element type="xs:byte" name="Vendor-Type-AC-Max"/>
<xs:element name="Vendor-Type-depends-on" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="EMP-Code"/>
<xs:element type="xs:string" name="EMP-Id"/>
<xs:element type="xs:string" name="EMP-Name"/>
<xs:element name="EMP-Details" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Property-Code"/>
<xs:element type="xs:string" name="Cash-Code"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
Excel表输入:
Sample
Sample-List
Id
Version
Name
Vendor
Vendor-Id
Vendor-Name
Vendor-Type
Vendor-Type-Id Vendor-Type-Code Vendor-Type-Mode Vendor-Type-AC-Min Vendor-Type-AC-Max
AAAA-1 AAAA-2 Active 1 4
BBBB-1 BBBB-2 Active 1 4
CCCC-1 CCCC-2 Active 1 4
DDDD-1 DDDD-2 Active 1 4
Vendor-Type-depends-on
EMP-Code EMP-Id EMP-Name
AAAA-3 AAAA-4 AAAA-5
NIL NIL NIL
NIL NIL NIL
DDDD-3 DDDD-4 DDDD-5
EMP-Details Property-Code Cash-Code
AAAA-6 AAAA-7
NIL NIL
NIL NIL
DDDD-6 DDDD-7