Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何合并2XSD模式_Php_Xml_Xsd - Fatal编程技术网

Php 如何合并2XSD模式

Php 如何合并2XSD模式,php,xml,xsd,Php,Xml,Xsd,我有2个xsd模式需要合并 F.e 下一次会议的结果: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="UserType"> <xs:sequence> <xs:element t

我有2个xsd模式需要合并 F.e

下一次会议的结果:

<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:complexType name="UserType">
            <xs:sequence>
                <xs:element type="xs:string" name="Field1"/>
                <xs:element type="xs:string" name="Field6"/>
            </xs:sequence>
        </xs:complexType>
        <xs:schema>
            <xs:complexType name="UserType">
            <xs:sequence>
                <xsd:element type="xsd:string" name="Field1"/>
                <xsd:element type="xsd:string" name="Field2"/>
                <xsd:element type="xsd:string" name="Field3"/>
            </xs:sequence>
        </xs:complexType>
        </xs:schema>
    </xs:schema>

我不需要从子文件解析到父节点,但我不知道如何从结果文件中删除它


有人能帮帮我吗?!谢谢

看来我找到了解决办法

$first = new \DOMDocument("1.0", 'UTF-8');
$first->formatOutput = true;
$first->loadXML($parent);

$second = new \DOMDocument("1.0", 'UTF-8');
$second->formatOutput = true;
$second->loadXML($child);
$second = $second->documentElement;

foreach($second->childNodes as $node)
{
    $importNode = $first->importNode($node,TRUE);
    $first->documentElement->appendChild($importNode);
}
echo $first->saveXML();

最后第三个XML文档(
$XML
)的基本原理是什么?例如,
$first
不应该包含这个吗?是的。你是对的。不需要。我把它删掉了
<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:complexType name="UserType">
            <xs:sequence>
                <xs:element type="xs:string" name="Field1"/>
                <xs:element type="xs:string" name="Field6"/>
            </xs:sequence>
        </xs:complexType>
        <xs:schema>
            <xs:complexType name="UserType">
            <xs:sequence>
                <xsd:element type="xsd:string" name="Field1"/>
                <xsd:element type="xsd:string" name="Field2"/>
                <xsd:element type="xsd:string" name="Field3"/>
            </xs:sequence>
        </xs:complexType>
        </xs:schema>
    </xs:schema>
$first = new \DOMDocument("1.0", 'UTF-8');
$first->formatOutput = true;
$first->loadXML($parent);

$second = new \DOMDocument("1.0", 'UTF-8');
$second->formatOutput = true;
$second->loadXML($child);
$second = $second->documentElement;

foreach($second->childNodes as $node)
{
    $importNode = $first->importNode($node,TRUE);
    $first->documentElement->appendChild($importNode);
}
echo $first->saveXML();