使用 PHP 和 PHP 解析从 OPS 专利数据库返回的复杂 XML简单XML
我一直对 SimpleXML 着迷,试图将值放入可用的 PHP 变量中,这让我发疯。
我真诚地希望你们中一些更有才华的程序员能够帮助我...... 我将尽可能彻底...
我正在使用开放专利服务 API。使用以下 URL,我可以轻松生成包含我需要的所有数据的格式化 XML 文件。
<?php
// Patent Reference Number
$ref = "EP2359415";
// URL for XML response
$url = "http://ops.epo.org/2.6.2/rest-services/published-data/publication/epodoc/".$ref."/biblio";
// Reading the XML Response
$sitemap = new SimpleXMLElement($url);
// Echo out values from the XML Data
foreach($needhelp as $here) {
echo "Need Help Here!";
// Will be taking data and placing into a database here...
} ?>
如果您看到该网址... http://ops.epo.org /2.6.2/rest-services/published-data/publication/epodoc/EP2359415/biblio
您将看到返回的 XML 有多复杂 是。 基本上我无法通过 php 循环从数据中获取任何值...
任何帮助将不胜感激... 院长
I have been going crazy with SimpleXML trying to get values into usable PHP variables and it's driving me insane.
I am genuinely hoping some of you more talented coders out there can help me out...
I will be as thorough as I can...
I am using the Open Patent Service API. Using the following URL I can easily generate a formatted XML file with all the Data I need.
<?php
// Patent Reference Number
$ref = "EP2359415";
// URL for XML response
$url = "http://ops.epo.org/2.6.2/rest-services/published-data/publication/epodoc/".$ref."/biblio";
// Reading the XML Response
$sitemap = new SimpleXMLElement($url);
// Echo out values from the XML Data
foreach($needhelp as $here) {
echo "Need Help Here!";
// Will be taking data and placing into a database here...
} ?>
If you see the URL...
http://ops.epo.org/2.6.2/rest-services/published-data/publication/epodoc/EP2359415/biblio
You will see how complicated the XML returned is.
Basically I cannot get any values out of the data via php loops...
Any help would be greatly appreciated...
Dean
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个老问题,但我永远无法让 SimpleXML 做任何事情。鉴于这是在 Google 搜索中出现的关于在 PHP 中使用欧洲专利 Office API 的唯一内容,我想我应该记录一下对我有用的内容...
以下是我解决它的方法:
现在你有一个标准的 PHP 数组(
$patent_array
) 您可以迭代。请注意,这与我的代码类似,但不完全相同 - 如果您剪切/粘贴,您可能需要对其进行调整...当然,您仍然需要弄清楚如何处理委员会设计的极其复杂的代码数据结构,但至少它是可变的形式。编辑:
在尝试获得更复杂的结果时,很明显 EPO 数据不是严格的 XML。 SimpleXML&上面的代码在尝试解析结果时什么都不做。解决方案是使用容错的 DOM XML 解析器。我使用的代码如下所述: http://set.cooki .me/archives/225/php-dom-xml-to-array
I know this is an old question, but I could never get SimpleXML to do anything. Given that this is the only thing that comes up in a Google search about using the European Patent OFfice API with PHP, I thought I'd document what worked for me...
Here's how I solved it:
Now you have a standard PHP array (
$patent_array
) you can iterate through. Note that this is similar to my code, but not exactly the same - you may have to tweak it if you cut/paste... Of course, you still have to figure out what to do with the ridiculously complex designed-by-committee data structure, but at least it's in mugable form.Edit:
While trying to get more complex results, it became clear that EPO data is not strict XML. SimpleXML & the above code both do nothing when trying to parse results. The solution was to use a DOM XML parser, which is fault tolerant. The code I used is described here: http://set.cooki.me/archives/225/php-dom-xml-to-array