简体   繁体   中英

Converting XML from one structure to another structure

I want to convert the following xml structure

<so_product company="Brady Europe EN" part_number="N008153" category="Brady Europe English.Safety Identification.Pipe Markers &amp; Valve Identification.CLP Pipe Markers" description="CLP Pipe Marker on Roll - Hydrazine 127X33RL-T3-P19" >
<image zip_file_key="1" filename="794640.jpg"/>
<so_product_attribute name="Product Number" value="Hydrazine 127X33RL-T3-P19"/>
<so_product_attribute name="QTY/UOM" value="220/Roll"/>
<so_product_attribute name="Brady Material Number" value="B-7541"/>
<so_product_attribute name="Class" value="Flamable / non flamable liquids / Oils"/>
<so_product_attribute name="Colour" value="White on Brown"/>
<so_product_attribute name="Layout" value="3"/>
<so_product_attribute name="Legend" value="Hydrazine"/>
<so_product_attribute name="Material Type" value="Laminated Polyester"/>
<so_product_attribute name="Size - Height (mm)" value="33"/>
<so_product_attribute name="Size - Width (mm)" value="127"/>
<so_product_attribute name="Type" value="DANGER"/>
<so_product_attribute name="Danger Symbol" value="CLP 2^CLP 6^CLP 8^CLP 5^CLP 9"/>

to the following format

<?xml version="1.0" encoding="utf-8"?>

<stockItems>
    <stockItem>
        <reference>12345A2HC101</reference>
        <stockGroup>Brady Europe English.Data Collection &amp; RFID.Barcode Scanners &amp; Hardware"</stockGroup>
        <webListingImageUF>webFolder/images/productXSmall.gif(image@filename)</webListingImageUF>
        <webListingTextOrHTML>Listing description</webListingTextOrHTML>
        <webMoreInfoImageUF>webFolder/images/productXLarge.gif(image@filename)</webMoreInfoImageUF>
        <webMoreInfoTextOrHTML>Long Description</webMoreInfoTextOrHTML> 
    </stockItem>
</stockItems>

"so product" need to be converted to "stockItem". the value of the attribute "part_number" need to be included within the "reference" tag. the value of the attribute "filename" which is in the "image" tag need to be included within the "webListingImageUF" tag etc. How can do this? My file size of the xml file is 29MB where a lot of "so_product" get repeats.

I tried using XPath, a memory error came. Currently I am trying this using javax.xml.stream Interface XMLStreamReader, Here i first converted the tag names as to the tag names I wanted(example "so_product" to "stockItem", "image" to "reference" ) Now I want to include the "part_number" attribute value within the "reference" tag.

Please help me out..I want to submit this by today.

It looks like a pretty simple problem to solve in a few lines of XSLT, but you haven't supplied enough detail to see whether any aspects of the transformation are tricky: it's hard to see the relationship between your input and your output. 29Mb isn't a problem for XSLT nowadays.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM