Accessing Node of an XML object
I am trying to access certain pieces of data from an xml file, here is the problem.
###XML FILE
<products>
<product>
....
....
</product>
<product>
....
....
</product>
etc...
</products>
I know that the piece of data I need is in ($products->开发者_C百科;product->myProdNode
) I have this mapping (and many others) stored in my database as a string e.g.'product->prodCode
' or 'product->dedscriptions->short_desc
' How can I access this data by using the strings stored in my database.
Thanks for you help in advance!
I think if you replace your -> with forward slash (/), they effectively become Xpath and you can query Node contents like that.
E.g
'product->dedscriptions->short_desc' should be mapped to
'product/dedscriptions/short_desc'
Please read more on Xpath here
E.g. In C#
XmlNode.SelectSingleNode("product/dedscriptions/short_desc").InnerText will get the short description text
In php
$result = $record->xpath('descriptions/short_description');
while(list( , $node) = each($result)) { echo 'Results is: ',$node,"\n"; }
精彩评论