Using XMLReader and getting a bit stuck

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #1

    Using XMLReader and getting a bit stuck

    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
    Code:
    $this->lcNZResponse	=	$loRequest->getResponseBody(); 
    		
    		$loXMLReader		=	new XMLReader() ;
    		$loXMLReader->xml($this->lcNZResponse) ;
    		$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.

    Cheers
    nathj
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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.

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by Markus
      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!.
      That part is a bit of a pain. do you have any alternative suggestions?

      Cheers
      nathj

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        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.

        Cheers
        nathj

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          you could use SimpleXML (so you can use XPath).

          regards

          Comment

          • nathj
            Recognized Expert Contributor
            • May 2007
            • 937

            #6
            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.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              note: SimpleXML is of no use when you have namespaces around (well if I remember right) then you have to use DOMDocument or related.

              regards

              Comment

              Working...