首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取xml的xmlSchema?

获取xml的xmlSchema?
EN

Stack Overflow用户
提问于 2011-05-30 21:01:38
回答 1查看 450关注 0票数 2

我有包含以下内容的file.xml:

代码语言:javascript
复制
<?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中获取此信息吗

代码语言:javascript
复制
<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">
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-30 21:08:16

使用SimpleXML获取如下名称空间:

代码语言:javascript
复制
$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);

此代码将生成:

代码语言:javascript
复制
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', )

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6176614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档