Well, the time has come for me to ask another question, I hope someone can help.
Here’s the deal, I need to read a specific node from an XML message that is stored in a string. I figure XMLReader is the way to go.
I know that the node in question will contain either ‘True’ or ‘False’ which is perfect for my project.
Here’s my code
$this->lcNZResponse = $loRequest->getResponseBody();
$loXMLReader = new XMLReader() ;
$lcTestString = $loXMLReader->getAttribute("Message") ;
if(strToLower($lcTestString) == "true")
$llReturn = true ;
return $llReturn ;
I know the response has a node in it called ‘Message’ but I can’t seem to get the value out of it.
I have run the return through intVal() which for true should return 1, but even when I know the XML node contains ‘True’ the return is always false.
I hope that makes sense, and I hope someone can help me.
Wish I could be of help, but I can’t! Never used XMLReader, and looking at it’s documentation, I can see why people wouldn’t: there’s barely any documentation!
Maybe someone else will be of service.
That part is a bit of a pain. do you have any alternative suggestions?
Well, I would really like to use the XMLReader stuff as it seems the proper way to do things. But the documentation baffles me and I can’t get it to work. so I have resorted to testing the XML like a simple string. Using strpos() I am able to determine if the bit I want is there.
It may be crude, it may not be transferable but at present it works and that’s my main aim.
If anyone does know how to use the XMLReader stuff then please let me know, I hate using a fudge and that’s what my solution feels like.
you could use SimpleXML (so you can use XPath).
I nice idea, I’ll have a play around with that as it could make the code much more transferable – always good when you work on multiple projects.
note: SimpleXML is of no use when you have namespaces around (well if I remember right) then you have to use DOMDocument or related.