我有这样的 XML:
<StockInfo>
<Item>
<stockcode>111111</stockcode>
<vehicle>Ford</vehicle>
<model>Escape (2000-)~Maverick (2001-)</model>
<width>8</width>
<wheel_size>18</wheel_size>
<offset>35</offset>
<bolt_pattermn>5x114.3</bolt_pattermn>
<brand>ANTERA</brand>
<Velg_ID/>
<kit1>DK-135259671 x1</kit1>
<kit2/>
<kit3/>
<kit4/>
<qty_available>3.00000000</qty_available>
<price>1110.00</price>
<picture>410110
</picture>
</Item>
<Item>
<stockcode>111111</stockcode>
<vehicle>Honda</vehicle>
<model>Civic (5skr,2001-2006)(2006-)~Accord (2003-2008)~Acord Coupe (1999-)~Acord Type R~Civic Type R (2001-2006)(2007-,17"<)~Civic Type S (2001-2006)(2007-,17"<)~Integra Type R~Prelude (1997-2001)~Legend (1991-1999)</model>
<width>8</width>
<wheel_size>18</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x114.3</bolt_pattermn>
<brand>ANTERA</brand>
<Velg_ID/>
<kit1>DK-135259641 x1</kit1>
<kit2/>
<kit3/>
<kit4/>
<qty_available>3.00000000</qty_available>
<price>1110.00</price>
<picture>410110
</picture>
</Item>
<Item>
<stockcode>2222222</stockcode>
<vehicle>BMW</vehicle>
<model>6 (e63/64, 2004-2011)~M6 (e63/64, 2004-2011)</model>
<width>9</width>
<wheel_size>18</wheel_size>
<offset>15</offset>
<bolt_pattermn>5x120</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Ares</Velg_ID>
<kit1>DK-ZJB3 x1</kit1>
<kit2/>
<kit3/>
<kit4/>
<qty_available>4.00000000</qty_available>
<price>151110.00</price>
<picture>41001
</picture>
</Item>
</StockInfo>
如您所见,有 2 个相同的项目(具有相同的股票代码;项目是汽车车轮)和 1 个不同的项目......对于每个不同的汽车型号,相同的项目可以 X 次转换为 XML(如果这个车轮适用于奥迪 A3,奥迪 A4,雪铁龙 X,它将 3 次转化为 XML,所有其他元素(除了和具有相同的值))。
我的问题:
如何分离/拆分元素
<model>
:<model>Civic (5skr,2001-2006)(2006-)~Accord (2003-2008)~Acord Coupe (1999-)~Acord Type R~Civic Type R (2001-2006)(2007-,17"<)~Civic Type S (2001-2006)(2007-,17"<)~Integra Type R~Prelude (1997-2001)~Legend (1991-1999)</model>
成 X 元素<model>
<model>Civic (5skr,2001-2006)(2006-)</model>
<model>Accord (2003-2008)</model>
<model>Acord Coupe (1999-)</model>
<model>Acord Type R</model>
<model>Civic Type R (2001-2006)(2007-,17"<)</model>
<model>Civic Type S (2001-2006)(2007-,17"<)</model>
<model>Integra Type R</model>
<model>Prelude (1997-2001)</model>
<model>Legend (1991-1999)</model>
分隔符号是“~”
直到现在我都无法做到(既不使用 php,也不使用 xsl 转换)因此寻求帮助;-(
如何将相同的项目分组
<stockode>
为 1 个<Item>
根而不是 X?如何删除具有相同值的元素(正如我所说,如果车轮适用于许多汽车模型,那么它将在 XML 中多次使用不同的元素(有时也是
<vehicle>
- 但以防万一这个车轮只适用于少数汽车楷模))?
所以修改后的 XML 应该是这样的:
<StockInfo>
<Item>
<stockcode>111111</stockcode>
<vehicle>Ford</vehicle>
<model>Escape (2000-)~Maverick (2001-)</model>
<vehicle>Ford</vehicle>
<model>Civic (5skr,2001-2006)(2006-)</model>
<model>Accord (2003-2008)</model>
<model>Acord Coupe (1999-)</model>
<model>Acord Type R</model>
<model>Civic Type R (2001-2006)(2007-,17"<)</model>
<model>Civic Type S (2001-2006)(2007-,17"<)</model>
<model>Integra Type R</model>
<model>Prelude (1997-2001)</model>
<model>Legend (1991-1999)</model>
<wheel_size>18</wheel_size>
<offset>35</offset>
<offset>40</offset>
<bolt_pattermn>5x114.3</bolt_pattermn>
<brand>ANTERA</brand>
<Velg_ID/>
<qty_available>3.00000000</qty_available>
<price>1110.00</price>
<picture>410110
</picture>
</Item>
<Item><stockcode>2222222</stockcode>
<vehicle>BMW</vehicle>
<model>6 (e63/64, 2004-2011)</model>
<model>M6 (e63/64, 2004-2011)</model>
<model>M6 (e63/64, 2004-2011)</model>
<width>9</width>
<wheel_size>18</wheel_size>
<offset>15</offset>
<bolt_pattermn>5x120</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Ares</Velg_ID>
<qty_available>4.00000000</qty_available>
<price>151110.00</price>
<picture>41001
</picture>
</Item>
</StockInfo>