How to process data that cannot be read in simpleXMLobject

Source: Internet
Author: User
What if data cannot be read in simpleXMLobject? At the end of this post, joebnb edited class & nbsp; just {function & nbsp; xmlIn simpleXML object from 2014-02-2611: 01: 22. what should I do if the data cannot be read in the object?
This post was last edited by joebnb at 11:01:22
Class just {
Function xmlInclude ($ data ){
$ Xml = simplexml_load_file (dirname (_ FILE _). '/jump. XML ');
Foreach ($ xml-> Keyword-> xpath ("// * [data = '$ data']") as $ item ){
Return $ item;
}
}
}
$ TR = new just;
$ Cr = $ TR-> xmlInclude (query );
Print_r ($ cr );
$ Cr = (array) $ cr;
Echo'
';
Print_r ($ cr );

After writing simplexml parsing, print_r finds that simpleXML object is not an array.
SimpleXMLElement Object ([data] => query [page] => Array ([0] => dbcon. php [1] => select. php [2] => footer. php ))
Array ([data] => query [page] => Array ([0] => dbcon. php [1] => select. php [2] => footer. php ))

How to extract the values, Baidu's answer is to convert them into arrays, and I tried to do the same.
However
echo $cr[0].$cr[0][0].$cr[1][0]

Cannot get the value and prompt:
Notice: Undefined offset: 0 in D: \ Program files \ WEB Edit \ phpLight2013 \ WWW \ Core \ xml. php on line 23
Notice: Undefined offset: 0 in D: \ Program files \ WEB Edit \ phpLight2013 \ WWW \ Core \ xml. php on line 23

How can I directly obtain values from simplexml obj? How can I take an array like this?
------ Solution --------------------
$ Cr = $ TR-> xmlInclude (query );
$ Cr = (array) $ cr;
Echo $ cr ['data'];
Echo $ cr ['Page'] [1];

Note: $ cr = (array) $ cr; converts the first object to an array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.