2012-02-27 106 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来说不是问题。