I need XML Script Urgently ($20 via paypal to person that gives the solution!)

Discussion in 'PHP' started by UK-Networks, Sep 6, 2006.

  1. #1
    Hi All,

    I need a PHP script to parse the following XML structure into PHP variables with the same name as the variables, I have not got the time to learn how to do it, and it needs to be done tonight!

    The first person to post here with the working answer will get $20 by paypal.

    Rgds,
    Chris

    
    <?xml version="1.0" encoding="UTF-8"?>
    <ResponseBlock Type="Live">
    	<Response Type="ADSLChecker">
    		<OperationResponse>
    			<ErrorCode></ErrorCode>
    			<PhoneNo><02082622254></PhoneNo>
    			<FixedRate></FixedRate>
    			<RateAdaptive></RateAdaptive>
    			<ExchangeState></ExchangeState>
    			<FullMsg>testing</FullMsg>
    			<ExtraMsg>test</ExtraMsg>
    			<ExchangeCode></ExchangeCode>
    			<ExchangeName></ExchangeName>
    			<ReasonCode></ReasonCode>
                                          <ReadyDate></ReadyDate>
    			<RTPC></RTPC>
    		</OperationResponse>
    	</Response>
    </ResponseBlock>
    
    Code (markup):
     
    UK-Networks, Sep 6, 2006 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    here it the class :


    to use it :


    now to see results :

    You will have access to an array that contain your xml info .
     
    commandos, Sep 6, 2006 IP
  3. UK-Networks

    UK-Networks Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Soz,
    I forgot to meantion it wouldn't be from a file. I have recieved it into a variable from a CURL command can you update your code for that:)

    Rgds,
    Chris
     
    UK-Networks, Sep 6, 2006 IP
  4. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #4
    put this instead :



     
    commandos, Sep 6, 2006 IP
  5. UK-Networks

    UK-Networks Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    UK-Networks, Sep 11, 2006 IP
  6. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #6
    what is the url of the xml file ?
     
    commandos, Sep 13, 2006 IP
  7. UK-Networks

    UK-Networks Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    As I said, there is no file. It is a response from a CURL command to access a webservice
     
    UK-Networks, Sep 13, 2006 IP
  8. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #8
    yes the url of the xml ... can u past it .
     
    commandos, Sep 13, 2006 IP
  9. UK-Networks

    UK-Networks Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Working like this isn't going do. I have the need for the XML stuff in two scripts.

    If you want i'll pay you $50 to complete both scripts for me. I can provide full documentation for the XML webservice site.

    Please email me your MSN/AIM details if you are willing.

    Rgds,
    Chris
     
    UK-Networks, Sep 15, 2006 IP
  10. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #10
    Try following class.
    Please note I have changed this to work and tested on PHP5, from the original code found on phpclasses.com

    USAGE:
    $xAry = new xml2array($xmlstring);
    $resultarray = $xAry->getResult();
    print "<pre>\r\n";
    print_r($resultarray);
    print "</pre>";
    
    Code (markup):
    CLASS:
    class	xml2array
    {
    	function xml2array( $xml )
    	{
    		if ( is_string($xml) )
    		{
    			$responseDoc = new DomDocument();
    			if($responseDoc->loadXML($xml)) 
    				$this->root_element = $responseDoc->firstChild;
    		}
    		return FALSE;
    	}
    
    	function _recNode2Array( $domnode )
    	{
    		if ( $domnode->nodeType == XML_ELEMENT_NODE )
    		{
    			if ($domnode->hasChildNodes())
    			{
    				$childs = $domnode->childNodes;
    				for ($i = 0; $i < $childs->length; $i++)
    				{
    					$child = $childs->item($i);
    					if ($child->nodeType == XML_ELEMENT_NODE)
    					{
    						$subnode = false;
    						$prefix = ( $child->prefix ) ? $child->prefix.':' : '';
    						
    
    						for ($j = 0; $j < $childs->length; $j++)
    						{
    							$testnode = $childs->item($j);
    							if ( is_object($testnode) )
    							{
    								if ($child->nodeName == $testnode->nodeName && !$child->isSameNode($testnode))
    								{
    									$subnode = true;
    								}
    							}
    						}
    
    //						foreach ($childs as $testnode)
    //							if ( is_object($testnode) )
    //								if ($child->nodeName == $testnode->nodeName && $child != $testnode)
    //									$subnode = true;
    								
    						if ( is_array($result[ $prefix.$child->nodeName ]) ) $subnode = true;
    						if ($subnode == true)
    							$result[ $prefix.$child->nodeName ][]	= $this->_recNode2Array($child);
    						else
    							$result[ $prefix.$child->nodeName ]	= $this->_recNode2Array($child);
    					}
    				}
    			}
    	
    			if ( !is_array($result) )
    			{
    				$result['evalue']	=	$domnode->nodeValue;
    			}
    	
    			if ( $domnode->hasAttributes() )
    				foreach ( $domnode->attributes as $attrib )
    				{
    					$prefix = ( $attrib->prefix ) ? $attrib->prefix.':' : '';
    					$result["@".$prefix.$attrib->name]	=	$attrib->value;
    				}
    			return $result;
    		}
    	}
    
    	function getResult()
    	{
    		if ( $resultDomNode = $this->root_element )
    		{
    			$array_result[ $resultDomNode->tagName ] = $this->_recNode2Array( $resultDomNode );
    			return $array_result;
    		} 
    		else return false;
    	}
    }
    Code (markup):
     
    harsh789, Sep 16, 2006 IP