加入或合并两个xml文档并匹配内容

时间:2016-06-30 13:24:17

标签: php xml simplexml

我有两个xml文档

sample1.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<hard-timeout>0</hard-timeout>
<idle-timeout>0</idle-timeout>
<priority>10</priority>
<flow-name>ssh_flow</flow-name>
<match>
    <ethernet-match>
        <ethernet-type>
            <type>2048</type>
        </ethernet-type>
    </ethernet-match>
    <ipv4-destination>192.168.4.1/24</ipv4-destination>
    <ip-match>
        <ip-protocol>6</ip-protocol>
        <ip-dscp>2</ip-dscp>
        <ip-ecn>2</ip-ecn>
    </ip-match>
    <tcp-destination-port>22</tcp-destination-port>
    <in-port>1</in-port>
</match>
<id>1</id>
<table_id>0</table_id>
<instructions>
    <instruction>
        <order>0</order>
        <apply-actions>
            <action>
                <drop-action/>
                <order>0</order>
            </action>
        </apply-actions>
    </instruction>
</instructions>
</flow>

sample2.xml

 Caused by: org.apache.spark.api.python.PythonException: Traceback (most recent call last):
File "/opt/cloudera/parcels/CDH-5.7.0-1.cdh5.7.0.p0.45/lib/spark/python/pyspark/worker.py", line 64, in main
("%d.%d" % sys.version_info[:2], version))
Exception: Python in worker has different version 2.6 than that in driver 3.5, PySpark cannot run with different minor versions

我的目标是通过匹配id来将两个xml文件连接到一个文件中。 那样:

<products>
    <product>
        <productid>001</productid>
        <title>Apple</title>
    </product>
    <product>
        <productid>002</productid>
        <title>Samsung</title>
    </product>
</products>

我只是找到合并两个xml文件的方法,但输出不是那样的。 任何想法都会有所帮助。谢谢。

0 个答案:

没有答案