Need help in reading XML data

Discussion in 'PHP' started by greatlogix, Jan 31, 2011.

  1. #1
    <po-response xsi:schemaLocation="http://seller.xxxxxxx.xxx.com/xx/xx https://seller.xxxxxxx.xxx.com/xx/xx-v2.xsd">
    −
    <purchase-order>
    <po-number>55555</po-number>
    <po-date>2011-01-27</po-date>
    <expected-ship-date>2011-01-31</expected-ship-date>
    −
    <shipping-detail>
    <ship-to-name>John Smith</ship-to-name>
    <address>123 SUNRISE AVE NY</address>
    <city>NEW YORK</city>
    <state>NY</state>
    <zipcode>98311</zipcode>
    <phone>11111111</phone>
    <shipping-method>Ground</shipping-method>
    </shipping-detail>
    <customer-name>John Smith</customer-name>
    −
    <po-line>
    −
    <po-line-header>
    <line-number>1</line-number>
    <item-id>cC-W2W61</item-id>
    <item-name>Fabric - XXXXXX</item-name>
    <item-sell-price>14.99</item-sell-price>
    <order-quantity>1</order-quantity>
    </po-line-header>
    −
    <po-line-detail>
    <po-line-status>NEW</po-line-status>
    <quantity>1</quantity>
    Code (markup):
    Can you please help me in reading values from this XML file

    I am trying using following code.
    
    $str = "https://www.example.com/xml/";
    	$output = file_get_contents($str);
    	$xmlOBJ = simplexml_load_string($output);
    $ord_no = (string) $xmlOBJ->purchase-order->po-number;
    
    PHP:
    getting this error :mad:
    syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'

    Can you please help me getting vaule "55555"
     
    greatlogix, Jan 31, 2011 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It should be
    
    $ord_no = (string) $xmlOBJ->{"purchase-order"}->{"po-number"};
    
    PHP:
    you cannot use sign "-" in property name.
     
    Greg Carnegie, Jan 31, 2011 IP
    greatlogix likes this.
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    Thanks Greg Carnegie. It worked. Rep added
     
    greatlogix, Jan 31, 2011 IP