gpt4 book ai didi

php - 获取xml的xmlSchema?

转载 作者:行者123 更新时间:2023-12-04 06:24:39 25 4
gpt4 key购买 nike

我有 file.xml 包含:

<?xml version="1.0"?>
<Document xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:test.001.001.01">
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</Document>

有人知道我如何在 <document....> 中获得此信息例如 xmlns ?
<Document xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:test.001.001.01">

最佳答案

使用 SimpleXML像这样获得命名空间:

$xmlstr = <<<XML
<?xml version="1.0"?>
<Document xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:test.001.001.01">
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</Document>
XML;

$xml = simplexml_load_string($xmlstr);
$namespaces = $xml->getDocNamespaces();
var_export($namespaces);

此代码将产生:
array ( 'xsd' => 'http://www.w3.org/2001/XMLSchema', 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', '' => 'urn:iso:std:iso:20022:tech:xsd:test.001.001.01', )

文档中声明的所有命名空间的数组。

关于php - 获取xml的xmlSchema?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6176614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com