首先,我需要通过xml文档中的特定子节点值查找父节点;然后将一些特定的子节点从父节点复制到另一个xml文档。PHP将xml节点从一个文档复制到另一个文档
例如:
DESTINATION FILE: ('destination.xml')
<item>
<offerStartDate>2012-15-02</offerStartDate>
<offerEndDate>2012-19-02</offerEndDate>
<title>Item Title</title>
<rrp>14.99</rrp>
<offerPrice>9.99</offerPrice>
</item>
和
SOURCE FILE: ('source.xml')
<items>
<item>
<title>Item A</title>
<description>This is the description for Item A</description>
<id>1003</id>
<price>
<rrp>10.00</rrp>
<offerPrice>4.99</offerPrice>
</price>
<offer>
<deal>
<isLive>0</isLive>
</deal>
</offer>
</item>
<item>
<title>Item B</title>
<description>This is the description for Item B</description>
<id>1003</id>
<price>
<rrp>14.99</rrp>
<offerPrice>9.99</offerPrice>
</price>
<offer>
<deal>
<isLive>1</isLive>
</deal>
</offer>
</item>
<item>
<title>Item C</title>
<description>This is the description for Item C</description>
<id>1003</id>
<price>
<rrp>9.99</rrp>
<offerPrice>5.99</offerPrice>
</price>
<offer>
<deal>
<isLive>0</isLive>
</deal>
</offer>
</item>
我想找到有它的子节点<isLive>
值设置为 “1” 的父节点<item>
。然后将父节点的其他子节点复制到目标xml。
例如如果父节点<item>
将其子节点<isLive>
设置为1.复制<title>
,<rrp>
和<offerPrice>
节点及其值,并将它们作为子节点添加到目标文件,如上所示。
如果我没有正确使用它们,请原谅我的技术术语。
非常感谢帮助家伙!
我假设你destination.xml有一个项目的根节点,太? – Gordon 2012-02-16 12:10:31
是的,它' '。现在处理它,谢谢 –
echez
2012-02-16 14:30:36