Java 如何创建动态XML';从XSD迭代字典键中删除?

Java 如何创建动态XML';从XSD迭代字典键中删除?,java,python-3.x,xml,dictionary,xml-parsing,Java,Python 3.x,Xml,Dictionary,Xml Parsing,如何从XSD迭代字典键创建动态XML。我试着用下面的代码对值进行编码。需要关于如何迭代字典和创建XML的帮助 代码: import xmlschema import json from xml.etree.ElementTree import ElementTree my_xsd = '<?xml version="1.0"?>' \          '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">'

如何从XSD迭代字典键创建动态XML。我试着用下面的代码对值进行编码。需要关于如何迭代字典和创建XML的帮助

代码:

import xmlschema
import json
from xml.etree.ElementTree import ElementTree

my_xsd = '<?xml version="1.0"?>' \
         '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">' \           
         '<xsd:element name="ISA" type="xsd:string"/>' \
         '</xsd:schema>'

schema = xmlschema.XMLSchema(my_xsd)
data = json.dumps({'ISA': '01'})


xml = xmlschema.from_json(data, schema=schema, preserve_root=True)

ElementTree(xml).write('D:/my_xml.xml') 
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">         
<xsd:element name="ISA0" type="xsd:string"/>
</xsd:schema>
output.xml

<ISA0>ISA</ISA0>
<ISA1>01</ISA1>
<ISA1>02</ISA1> 
模式:

import xmlschema
import json
from xml.etree.ElementTree import ElementTree

my_xsd = '<?xml version="1.0"?>' \
         '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">' \           
         '<xsd:element name="ISA" type="xsd:string"/>' \
         '</xsd:schema>'

schema = xmlschema.XMLSchema(my_xsd)
data = json.dumps({'ISA': '01'})


xml = xmlschema.from_json(data, schema=schema, preserve_root=True)

ElementTree(xml).write('D:/my_xml.xml') 
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">         
<xsd:element name="ISA0" type="xsd:string"/>
</xsd:schema>
output.xml

<ISA0>ISA</ISA0>
<ISA1>01</ISA1>
<ISA1>02</ISA1> 

         
输出:

import xmlschema
import json
from xml.etree.ElementTree import ElementTree

my_xsd = '<?xml version="1.0"?>' \
         '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">' \           
         '<xsd:element name="ISA" type="xsd:string"/>' \
         '</xsd:schema>'

schema = xmlschema.XMLSchema(my_xsd)
data = json.dumps({'ISA': '01'})


xml = xmlschema.from_json(data, schema=schema, preserve_root=True)

ElementTree(xml).write('D:/my_xml.xml') 
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">         
<xsd:element name="ISA0" type="xsd:string"/>
</xsd:schema>
output.xml

<ISA0>ISA</ISA0>
<ISA1>01</ISA1>
<ISA1>02</ISA1> 
output.xml
伊萨
01
02