Parsing Amazon MWS Scratchpad response(解析亚马逊 MWS Scratchpad 响应)
问题描述
我正在尝试解析来自亚马逊的 xml 文件,但遇到了困难.我正在使用 simplexml_load_string
I am trying to parse xml file from amazon but found difficulties. I am using simplexml_load_string
$xml = simplexml_load_string('我的xml在这里');
$xml = simplexml_load_string( 'My xml here' );
但是当我这样做时
echo $xml->GetMatchingProductResult->Product->AttributeSets;
echo $xml->GetMatchingProductResult->Product->AttributeSets;
什么都不显示
如何获取品牌价值?
我的 xml 文件:
推荐答案
我知道这是一个老问题,但我遇到了同样的问题.
I know this is an old question but I had a hard time with the same thing.
首先 simplexml_load_string 不会像这样处理抛出的命名空间,因此您可以递归检查然后加载命名空间,评估 xml 并浪费大量时间...
First simplexml_load_string doesn't handle the namespaces thrown in like this, so you could go recursively and check and then load the namespaces, evaluate the xml and waste a lot of time ...
就我而言,我并不关心使用命名空间评估 xml 的格式,所以我只是使用正则表达式将它们从字符串中删除.在这个 simplexml_load_string 之后不会再省略这些部分,并且使用 json_encode 和 json_decode 很容易从中得到一个数组.
In my case I didn't care about evaluating the format of the xml with the namespaces, so I just removed them from the string with regex. After this simplexml_load_string won't omit those parts anymore and it's easy to get an array out of it with json_encode and json_decode.
唯一的问题是当 xml 充满了包含有用数据的属性时,那么您将需要其他东西而不是 simplexml_load_string.请注意,它会从这里返回一个 @attributes 元素:
The only problem with this is when the xml is full of attributes containing useful data, then you would need something else instead of simplexml_load_string. Note that it returns an @attributes element from this:
但从这部分省略:
我不知道它为什么会检查嵌套标签或检查嵌套标签的深度.
I have no idea why or how deep down it would check in the nested tags.
这篇关于解析亚马逊 MWS Scratchpad 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!