2012-02-27 83 views
0

我想下面的XML結構從一個結構轉換XML到另一個結構

<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"/> 

轉換爲以下格式

<?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([email protected])</webListingImageUF> 
     <webListingTextOrHTML>Listing description</webListingTextOrHTML> 
     <webMoreInfoImageUF>webFolder/images/productXLarge.gif([email protected])</webMoreInfoImageUF> 
     <webMoreInfoTextOrHTML>Long Description</webMoreInfoTextOrHTML> 
    </stockItem> 
</stockItems> 

「這樣的產品」,需要轉換爲「stockItem」。屬性「part_number」的值需要包含在「reference」標籤中。 「圖片」標籤中屬性「文件名」的值需要包含在「webListingImageUF」標籤中。如何做到這一點?我的xml文件大小爲29MB,其中很多「so_product」重複。

我嘗試使用XPath,出現內存錯誤。目前我正在嘗試使用javax.xml.stream 接口XMLStreamReader,在這裏我首先將標記名稱轉換爲我想要的標記名稱(例如「so_product」爲「stockItem」,「image」爲「reference」)現在我想要在「參考」標籤中包含「part_number」屬性值。

請幫我...我想今天提交。

+0

我的文件大小xml文件是29MB,其中很多so_product標籤重複。 – user989128 2012-02-27 07:11:33

+0

還有4851 + 6518 + 6704 + 3244 標籤需要轉換爲xml文件 – user989128 2012-02-27 09:03:04

+0

。屬性「part_number」的值需要包含在標籤「reference tag」中。 「圖片」標籤中屬性「文件名」的值需要包含在「webListingImageUF」標籤中。如何做到這一點?我的xml文件大小爲29MB,其中有很多重複。 – user989128 2012-02-27 09:08:23

回答

3

在幾行XSLT中看起來像是一個非常簡單的問題,但是您沒有提供足夠的細節來查看轉換的任何方面是否棘手:很難看到您的輸入和您的輸入之間的關係輸出。現在29Mb對於XSLT來說不是問題。

相關問題