I am developing part of a web app which takes an XML schema as input to generate an XML file. There is also data to be put into the XML tags in an ordered way.
我正在开发一个Web应用程序的一部分,它采用XML模式作为输入来生成XML文件。还有一些数据以有序的方式放入XML标记中。
for example, I will have an ArrayList of 100 numbers, say, 1 to 100
例如,我将有一个100个数字的ArrayList,比如1到100
and the .xsd would look like the following example:
和.xsd看起来像下面的例子:
xs:element name="elt1"
xs:element name =“elt1”
xs:complexType
XS:复杂类型
xs:sequence
xs:element name="elt1-1"
xs:element name="elt1-2"
xs:element name="elt1-3"
xs:element name="elt1-4"
xs:element name="elt1-5"
xs:sequence
xs:complexType
XS:复杂类型
xs:element name="elt1"
xs:element name =“elt1”
......other elements
......其他元素
how can I generate an XML file like the following:
如何生成如下所示的XML文件:
< elt1>
< elt1-1>1< elt1-1>
< elt1-2>2< elt1-2>
< elt1-2>3< elt1-3>
< elt1-4>4< elt1-4>
< elt1-5>3< elt1-5>
< elt1>
so that data in each tag is the corresponding number in the arraylist, in the same order of the data in the arraylist?
以便每个标签中的数据是arraylist中相应的数字,与arraylist中的数据顺序相同?
I would really appreciate any suggestion or exmaple. Thanks in advance!
我真的很感激任何建议或exmaple。提前致谢!
2 个解决方案
#1
5
You can use the xsd2inst tool in XMLBeans to generate an xml document from a schema. If you're curious how XMLBeans does this, you can see how the xsd2inst tool is implemented:
您可以使用XMLBeans中的xsd2inst工具从架构生成xml文档。如果您对XMLBeans如何做到这一点感到好奇,您可以看到xsd2inst工具是如何实现的:
http://svn.apache.org/viewvc/xmlbeans/trunk/src/tools/org/apache/xmlbeans/impl/xsd2inst/
http://svn.apache.org/viewvc/xmlbeans/trunk/src/tools/org/apache/xmlbeans/impl/xsd2inst/
#2
0
Probably a duplicate of:
可能是以下副本:
how-to-generate-sample-xml-documents-from-their-dtd-or-xsd
如何对生成样本-XML的文档从 - 他们-DTD或 - XSD
and/or
和/或
XML instance generation from XML schema (xsd)
从XML模式生成XML实例(xsd)
Also, I'd recommend that you explain if you really want to use JAXB (since you tagged it), and explicitly state whether you want this behavior to be automated in your app, or whether it can be accommodated with manual steps / using external tools (e.g. xml editors).
此外,我建议你解释一下你是否真的想要使用JAXB(因为你标记了它),并明确说明你是否希望在你的应用程序中自动执行此行为,或者是否可以通过手动步骤/使用外部来适应工具(例如xml编辑器)。
#1
5
You can use the xsd2inst tool in XMLBeans to generate an xml document from a schema. If you're curious how XMLBeans does this, you can see how the xsd2inst tool is implemented:
您可以使用XMLBeans中的xsd2inst工具从架构生成xml文档。如果您对XMLBeans如何做到这一点感到好奇,您可以看到xsd2inst工具是如何实现的:
http://svn.apache.org/viewvc/xmlbeans/trunk/src/tools/org/apache/xmlbeans/impl/xsd2inst/
http://svn.apache.org/viewvc/xmlbeans/trunk/src/tools/org/apache/xmlbeans/impl/xsd2inst/
#2
0
Probably a duplicate of:
可能是以下副本:
how-to-generate-sample-xml-documents-from-their-dtd-or-xsd
如何对生成样本-XML的文档从 - 他们-DTD或 - XSD
and/or
和/或
XML instance generation from XML schema (xsd)
从XML模式生成XML实例(xsd)
Also, I'd recommend that you explain if you really want to use JAXB (since you tagged it), and explicitly state whether you want this behavior to be automated in your app, or whether it can be accommodated with manual steps / using external tools (e.g. xml editors).
此外,我建议你解释一下你是否真的想要使用JAXB(因为你标记了它),并明确说明你是否希望在你的应用程序中自动执行此行为,或者是否可以通过手动步骤/使用外部来适应工具(例如xml编辑器)。