匹配XML文件并传输标记值?

时间:2017-04-15 21:25:35

标签: xml match simplexml

我有两个XML文件,我想将指定的值从一个XML文件传输到名称匹配的另一个XML文件。如果游戏没有匹配的值,我想要添加标签,但它应该是空的。

有人知道我该怎么做吗?

以下是一个例子:

data.xml中

<products>
    <product>
        <title>iPhone 7</title>
        <desc>Here is a desc</desc>
    </product>
    <product>
        <title>iPhone 6</title>
    </product>
</products>

我想在名称匹配的XML文件中传输desc的值。如果desc文件中的data.xml中没有值,我想将""添加到here.xml文件中。像这样:

here.xml

<products>
    <product>
        <title>iPhone 7</title>
        <desc>Here is a desc</desc>
    </product>
    <product>
        <title>iPhone 6</title>
        <desc></desc>
    </product>
</products>

问候,谢谢!

0 个答案:

没有答案