homepage Welcome to WebmasterWorld Guest from 54.145.191.14
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XML and HTML entities
surrealillusions

5+ Year Member



 
Msg#: 4465578 posted 7:07 pm on Jun 14, 2012 (gmt 0)

Hey all,

I have some problems with HTML entities in XML.

The XML file I have doesn't like having or & signs in it, or the HTML entity equivalent.

I have this to read the XML file:

$file = "stuff.xml";
// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");


Whenever I have a single or & sign in, it throws the unable to load file error. Remove the signs out completely and it displays the XML content fine.

I would of thought that simply using some PHP to convert the characters would be sufficient, but as it fails in loading the XML to begin with, this can't be done. Other than manually changing all the and & to XML friendly entities (but I dont know of one for either sign), is there any other solution?

Thanks.

 

httpwebwitch

WebmasterWorld Administrator httpwebwitch us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4465578 posted 6:26 pm on Jun 15, 2012 (gmt 0)

enclose the content in a <![CDATA[]]> node.

<![CDATA[ your $<%& funny characters go here ]]>

CDATA is "character data", it's intended as an enclosure for data that should not be parsed as XML.

It's a good practice to use a CDATA node to enclose any string data, especially if it's user-generated data like names, addresses, comments etc.

[w3schools.com...]

ericlewis107



 
Msg#: 4465578 posted 11:38 am on Dec 18, 2012 (gmt 0)

I was using the XHTML doctype is because the entities in my xml will be identical to xhtml, ie the nodes contain standard markup. As there are rather a lot I didn't want to specify them all, and as the main W3C doctypes come prebuilt into Firefox, the user wouldn't have to download them each time.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved