How to parse xml which has some prefix before element name?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thulaseeram
    New Member
    • Sep 2006
    • 23

    #1

    How to parse xml which has some prefix before element name?

    Hi,

    How to parse the following type of xml

    Code:
      $xml = '<?xml version="1.0"?>
    			<a:multistatus xmlns:b="urn:uuid:c400-xsall/" 
    						   xmlns:e="urn:schemas:httpmail:" 
    						   xmlns:c="xml:" 
    						   xmlns:d="urn:schemas:calendar:" 
    						   xmlns:a="DAV:">
    			<a:response>
    				<a:href>http://testserver/exchange/test/calendar/testmail</a:href>
    				<a:propstat>
    					<a:status>HTTP/1.1 200 OK</a:status>
    					<a:prop>
    						<d:location>Test Location</d:location>
    						<e:subject>Test Subject</e:subject>
    						<d:dtstart b:dt="dateTime.tz">2010-12-13T07:00:00.000Z</d:dtstart>
    						<d:dtend b:dt="dateTime.tz">2010-12-13T08:00:00.000Z</d:dtend>
    						<d:busystatus>BUSY</d:busystatus>
    						<d:instancetype b:dt="int">2</d:instancetype>
    						<a:displayname>Test Name</a:displayname>
    					</a:prop>
    				</a:propstat>
    			</a:response>
    </a:multistatus>';
    I tried to use the following php code but it is not working for me
    Code:
     $dom = new DOMDocument;
       $dom->loadXML(utf8_encode($xml));
       foreach ($dom->getElementsByTagNameNS('urn:schemas:httpmail:', '*') as $response){
          $subjec = $response->getElementsByTagName("subject");
    	  echo "<br/>Display Name=".$subject  = $subjec->item(0)->nodeValue;
    		
       }
    please can any one help me in solving this

    Thanks in Advance
    Ram
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you cannot use a DOMNodeList (getElementsByT agNameNS()) with foreach(). you need to use for()/while().

    Comment

    Working...