获取xml的xmlSchema?

问题描述

| 我有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....>
示例the2ѭ中获得此信息吗?
<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\',)
文档中声明的所有名称空间的数组。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...