我是使用xml和xsd工作的新手。我想用暴食来创建Web服务客户端:PHP Web服务客户端:Guzzle和xsd
http://guzzlephp.org/index.html
我能够创建一个非常基本的客户端和1个指令以下这个教程:
http://guzzlephp.org/tour/building_services.html
的问题,我有如何让返回的XML变成更有用的格式。我使用的Web服务(和它的文档和XSD),可以在这里找到:
http://www.epo.org/searching/free/ops.html
我得到一个SimpleXMLElement。假设以下XML内容:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/2.6.2/style/exchange.xsl"?>
<ops:world-patent-data xmlns:ops="http://ops.epo.org" xmlns="http://www.epo.org/exchange" xmlns:ccd="http://www.epo.org/ccd" xmlns:xlink="http://www.w3.org/1999/xlink">
<ops:meta name="elapsed-time" value="30"/>
<exchange-documents>
<exchange-document system="ops.epo.org" family-id="19768124" country="EP" doc-number="1000000" kind="A1">
<bibliographic-data>
<publication-reference>
<document-id document-id-type="docdb">
<country>EP</country>
<doc-number>1000000</doc-number>
<kind>A1</kind>
<date>20000517</date>
</document-id>
<document-id document-id-type="epodoc">
<doc-number>EP1000000</doc-number>
<date>20000517</date>
</document-id>
</publication-reference>
<!-- a lot of content snipped -->
</bibliographic-data>
</exchange-document>
</exchange-documents>
</ops:world-patent-data>
我该如何非常简单地提取doc-number(在上面的XML的第11行)?
我想:它
$xpath = '/ops:world-patent-data/exchange-documents/exchange-document/bibliographic-data/publication-reference/document-id/doc-number';
$data = $result->xpath($xpath);
和变化,但$的数据始终是空数组。
跟着链接并补充说:$ result-> registerXPathNamespace( '交流', 'http://www.epo.org/exchange' );路径//交换:书目数据/出版物参考/文档编号/文档编号不起作用,但只是使用// exchange:doc-number作为Marc B建议的作品。我很困惑......编辑:好的第一条路径必须是//交换:书目数据/交换:出版物参考/交换:文档编号/交换:文件编号。现在有意义,我想到它,但有点详细... –
你还应该看看[Symfony2的CssSelector组件](http://symfony.com/doc/current/components/css_selector.html)它是用来生成XPath为你。希望这可以帮助。 – renoirb