我正在尝试将数据从xml转换为json格式,为此,我已经从xml输出中编写了xsd schema以将数据从xml转换为json。
以下是我需要转换为json的xml
<?xml version="1.0" encoding="UTF-8"?>
<SyncData>
<Employerid>12345</Employerid>
<ImporterEmail>abcdef@xyz.com</ImporterEmail>
<ReportEmail>abcdefggggg@xyz.com</ReportEmail>
<Employees>
<wd:WorkerSummary xmlns:is="java:com.workday.esb.intsys.xpath.
ParsedIntegrationSystemFunctions"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xdiff="urn:com.workday/esb/xdiff" xmlns:wd="urn:com.workday/bsvc">
<wd:ReferenceID/>
<wd:Name>abcdef,ghijklm</wd:Name>
<wd:Title/>
<wd:EmployeeId>JG00889</wd:EmployeeId>
<wd:EMail>sderf.rtyui@xyzz.com</wd:EMail>
<wd:AddressLine1>1400 Post Alm Tyui</wd:AddressLine1>
<wd:City>Bostonn</wd:City>
<wd:State>MC</wd:State>
<wd:Zip>11067</wd:Zip>
<wd:Country>AUS</wd:Country>
</wd:WorkerSummary>
</Employees>
</SyncData>
以下是我从上面提到的xml中定义的两个不同的xsd模式,我得到的每个都有不同的错误。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.your-company.com/WorkermapSchema"
xmlns:tns="http://www.your-company.com/WorkermapSchema"
elementFormDefault="qualified">
<xs:element name="WorkerSummary">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="ReferenceID" />
<xs:element type="xs:string" name="Name" />
<xs:element type="xs:string" name="Title" />
<xs:element type="xs:string" name="EmployeeId" />
<xs:element type="xs:string" name="EMail" />
<xs:element type="xs:string" name="AddressLine1" />
<xs:element type="xs:string" name="City" />
<xs:element type="xs:string" name="State" />
<xs:element type="xs:string" name="Zip" />
<xs:element type="xs:string" name="Country" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我使用此架构获得的错误如下
com.workday.esb.xmltojson.XmlToJsonException:未找到根元素类型“SyncData”
由于上述错误显示未找到根元素“SyncData”,因此我尝试使用根元素以其他方式定义模式,如下所示。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
microsoft-com:xml-msdata" xmlns:app1="urn:com.workday/bsvc">
<xs:import namespace="urn:com.workday/bsvc"></xs:import>
<xs:element name="SyncData">
<xs:complexType>
<xs:sequence>
<xs:element name="Employerid" type="xs:string" minOccurs="0" />
<xs:element name="ImporterEmail" type="xs:string" minOccurs="0" />
<xs:element name="ReportEmail" type="xs:string" minOccurs="0" />
<xs:element name="Employees" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="WorkerSummary" type="xs:string"/>
<xs:element name="ReferenceID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="SyncData" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
使用上面的xsd架构后,我没有收到与根元素“SyncData”相关的错误,但是我得到了一个不同的错误,我不明白它是什么,错误如下。
org.codehaus.stax2.typed.TypedXMLStreamException:[row,col]处的ParseError:[2,359]消息:使用Typed Access方法时,元素内容不能包含子START_ELEMENT
架构中有什么问题或错误是什么?
我已尝试多次尝试xsd架构以根据需要完美地执行它,但似乎缺少一些我不确定是否会导致失败。
答案 0 :(得分:0)
您可以使用此架构
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="SyncData">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Employerid" type="xsd:int" />
<xsd:element name="ImporterEmail" type="xsd:string" />
<xsd:element name="ReportEmail" type="xsd:string" />
<xsd:element name="Employees">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="wd:WorkerSummary">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="wd:ReferenceID" type="xsd:string" />
<xsd:element name="wd:Name" type="xsd:string" />
<xsd:element name="wd:Title" type="xsd:string" />
<xsd:element name="wd:EmployeeId" type="xsd:string" />
<xsd:element name="wd:EMail" type="xsd:string" />
<xsd:element name="wd:AddressLine1" type="xsd:string" />
<xsd:element name="wd:City" type="xsd:string" />
<xsd:element name="wd:State" type="xsd:string" />
<xsd:element name="wd:Zip" type="xsd:int" />
<xsd:element name="wd:Country" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>