-Questions about the PHPDomDocument function

Source: Internet
Author: User
-PHPDomDocument function problems this post was finally asked by Dana_Zhang at 2014-02-1700: 26: 13. if someone else gave me an XML format string, the tag contains & nbsp; & lt; & nbsp; or & nbsp; & gt; & nbsp; & help-questions about the PHP DomDocument function

This post was last edited by Dana_Zhang at 00:26:13

For help, what if someone else sends me an XML format string containing <or> or <my new DomDocument and loading it using the loadXML function ~~

To add this question, the PHP version I use is 5.2.17. IIS: 7.5. the server version is windows server 2008 R2.
------ Solution --------------------
Use html_entity_decode () and then new DomDocument
------ Solution --------------------
If the special characters <,>, and & are not in the CDATA mark and are not escaped, they are not XML
You can use the loadHTML method to load data.
------ Solution --------------------
Escape Problem?
------ Solution --------------------
$ Dom = new DOMDocument;
$ Dom-> loadXML (' I'm a test string. ');
If (! $ Dom ){
Echo 'error while parsing the document ';
Exit;
}

$ S = simplexml_import_dom ($ dom );

Echo $ s-> text;


------ Solution --------------------
if ( file_exists ( 'test.xml' )) {
$xml = simplexml_load_file ( 'test.xml' );

echo $xml->text;
} else {
exit( 'Failed to open test.xml.' );
}


Test. xml
 

I'm a test string.

------ Solution --------------------
First, determine whether your xml is a standard xml. you can go to the w3 website to check the xml specifications, which cannot contain these special characters.

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.