如何将多个记录转换为一个XML记录

问题描述:

这是XML数据源:如何将多个记录转换为一个XML记录

<SalesInRecord> 
     <ROW_NUM>8</ROW_NUM> 
     <BUY_QTY>5</BUY_QTY> 
     <HP_PRODUCT_ID>Apj45682#123</HP_PRODUCT_ID> 
     <LOCATION_ID>2-PQL-3403</LOCATION_ID> 
     <LOCATION_NAME>XYZ el</LOCATION_NAME> 
     <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
     <SUPPLIER_ID>2-PQL-3455</SUPPLIER_ID> 
    </SalesInRecord> 
    <SalesInRecord> 
     <ROW_NUM>5</ROW_NUM> 
     <BUY_QTY>5</BUY_QTY> 
     <PRODUCT_ID>Apj45683#123</PRODUCT_ID> 
     <LOCATION_ID>2-PQL-3403</LOCATION_ID> 
     <LOCATION_NAME>XYZ el</LOCATION_NAME> 
     <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
     <SUPPLIER_ID>2-PQL-3457</SUPPLIER_ID> 
    </SalesInRecord> 
    <SalesInRecord> 
     <ROW_NUM>6</ROW_NUM> 
     <BUY_QTY>5</BUY_QTY> 
     <PRODUCT_ID>Apj45684</PRODUCT_ID> 
     <LOCATION_ID/> 
     <LOCATION_NAME>XYZ XYZ</LOCATION_NAME> 
     <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
     <SUPPLIER_ID>2-PQL-3455</SUPPLIER_ID> 
    </SalesInRecord> 
    <SalesInRecord> 
     <ROW_NUM>7</ROW_NUM> 
     <BUY_QTY>5</BUY_QTY> 
     <PRODUCT_ID>Apj45685</PRODUCT_ID> 
     <LOCATION_ID/> 
     <LOCATION_NAME>XYZ XY</LOCATION_NAME> 
     <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
     <SUPPLIER_ID>2-PQL-3455</SUPPLIER_ID> 
    </SalesInRecord> 

当我试图解析下面XSD我居然也得到了错误 消息上面的数据:发生错误而解析:下面的根元素的文档中的标记也必须是形成

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="unqualified" 
attributeFormDefault="unqualified"> 
    <xs:element name="SalesInRecord"> 
    <xs:complexType> 
    <xs:sequence> 
    <xs:element name="ROW_NUM" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="BUY_QTY" type="xs:integer" nillable="true" minOccurs="0"/> 
    <xs:element name="PRODUCT_ID" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="LOCATION_ID" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="LOCATION_NAME" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="UNIT_BUY_PRICE" type="xs:decimal" nillable="true" minOccurs="0"/> 
    <xs:element name="GOODS_RECEIVED_DATE" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="TRANSACTION_CURRENCY" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="TRANSACTION_DATE" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="TRANSACTION_DOCUMENT_ID" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="TRANSACTION_DOCUMENT_TYPE" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_ADDR_ASIAN" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_ADDR_STATE" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_ADDR_TOWN" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_ID" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_ISO_COUNTRY_CODE" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_NAME" type="xs:string" nillable="true" minOccurs="0"/> 
    <xs:element name="SUPPLIER_POSTAL_CODE" type="xs:string" nillable="true" minOccurs="0"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
</xs:schema> 

请帮我解析上述数据

+0

您在该文档中有多个''元素,不包含''作为根元素。正确形成的XML文档只有** ONE **根元素,并且您有多个。 –

+0

如何将作为根元素添加到上述记录集中。当我试图通过XSLT转换添加 user1658369

+0

时,我遇到同样的错误对于@ MarcB而言,源XML无效,因为它没有根元素。 “解决”它是正确的,有效的XML最有可能意味着联系谁提供给你这个XML并要求他们验证它。 – ABach

上面提到的xml应该有一个根元素。大概是这样的

<SalesInData> 
    <SalesInRecord> 
    <ROW_NUM>8</ROW_NUM> 
    <BUY_QTY>5</BUY_QTY> 
    <HP_PRODUCT_ID>Apj45682#123</HP_PRODUCT_ID> 
    <LOCATION_ID>2-PQL-3403</LOCATION_ID> 
    <LOCATION_NAME>XYZ el</LOCATION_NAME> 
    <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
    <SUPPLIER_ID>2-PQL-3455</SUPPLIER_ID> 
    </SalesInRecord> 
    <SalesInRecord> 
    <ROW_NUM>5</ROW_NUM> 
    <BUY_QTY>5</BUY_QTY> 
    <PRODUCT_ID>Apj45683#123</PRODUCT_ID> 
    <LOCATION_ID>2-PQL-3403</LOCATION_ID> 
    <LOCATION_NAME>XYZ el</LOCATION_NAME> 
    <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
    <SUPPLIER_ID>2-PQL-3457</SUPPLIER_ID> 
    </SalesInRecord> 
    <SalesInRecord> 
    <ROW_NUM>6</ROW_NUM> 
    <BUY_QTY>5</BUY_QTY> 
    <PRODUCT_ID>Apj45684</PRODUCT_ID> 
    <LOCATION_ID/> 
    <LOCATION_NAME>XYZ XYZ</LOCATION_NAME> 
    <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
    <SUPPLIER_ID>2-PQL-3455</SUPPLIER_ID> 
    </SalesInRecord> 
    <SalesInRecord> 
    <ROW_NUM>7</ROW_NUM> 
    <BUY_QTY>5</BUY_QTY> 
    <PRODUCT_ID>Apj45685</PRODUCT_ID> 
    <LOCATION_ID/> 
    <LOCATION_NAME>XYZ XY</LOCATION_NAME> 
    <UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE> 
    <SUPPLIER_ID>2-PQL-3455</SUPPLIER_ID> 
    </SalesInRecord> 
<SalesInData> 

此外,为了SalesInData适用于您的XSLT,只是硬编码到您的要求。

<xsl:element name="SalesInData">Dump your required data </xsl:element>