[英]create xml using data from excel using macro
Here is my requirement - 1) I have an xml and corresponding xsd document 2) It's a complex xml with multiple elements and their hierarchy. 这是我的要求-1)我有一个xml和相应的xsd文档2)这是一个包含多个元素及其层次结构的复杂xml。 But there are only certain elements/fields that are important 3) I want to create an excel with these fields where user can enter data across multiple rows 4) When user clicks on create xml, separate xml should be created for each row 5) The xml created should contain all the elements (user entered + many more in original xml) 但是只有某些元素/字段很重要3)我想用这些字段创建一个excel,用户可以在其中跨多个行输入数据4)当用户单击create xml时,应为每行创建单独的xml 5)创建的xml应该包含所有元素(用户输入的内容以及原始xml中的更多内容)
This is just a Sample- 这只是一个示例
<A>
<A1/>
<A2/>
</A>
<B>
<B1>*User entered value*</B1>
<B2>*User entered value*</B2>
</B>
<C>
<C1/>
<C2/>
</C>
I found some references on MSXML2.DOMDocument60 where one can create xml using this API and also validate against schema through excel macro. 我在MSXML2.DOMDocument60上找到了一些参考,其中可以使用此API创建xml,也可以通过excel宏针对架构进行验证。 But in my case there are 1000s of tags. 但就我而言,有数千个标签。 Below are some options I have in mind- 以下是我想到的一些选项-
Appreciate any help on this. 感谢对此的任何帮助。 Thanks ! 谢谢 !
If you have a base, you can use something like that: 如果您有基础,则可以使用类似的方法:
Open "e:\0\xml.xml" For Input As #1
Open "e:\0\xml1.xml" For Output As #2
i = 1
While Not EOF(1)
Line Input #1, aa
If InStr(1, aa, "<B1>", vbTextCompare) > 0 Then
aa = Left(aa, 3 + InStr(1, aa, "<B1>", vbTextCompare)) & Cells(i, 1).Value & Right(aa, Len(aa) - InStr(1, aa, "</B1>", vbTextCompare) + 1)
i = i + 1
End If
Print #2, aa
Wend
Close #1
Close #2
the code copy the original file, changing the text inside the tag B1 with the values in column A. 代码复制原始文件,使用A列中的值更改标签B1中的文本。
If you have more "pieces", you can merge different files... 如果您有更多“片段”,则可以合并不同的文件...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.