1

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->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!

1 Answer 1

2

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"; }

Sign up to request clarification or add additional context in comments.

3 Comments

How would i get the data with this method?
$record->xpath('descriptions/short_description'); - I want just the value not the SimpleXMLElement Object
Am not sure about the properties and methods of SimpleXMLElement Object, but you should access the inner text or value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.