get xmlSchema of xml?
I have the file.xml contains:
<?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>
anybody know How Can I get this information in the <document....>
example the 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">
Use SimpleXML to get namespaces like so:
$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);
this code will produce:
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', )
The array of all namespaces declared in the document.
精彩评论