Reputation: 13
I am very very new to xml. I am developing an application which uses xml file. I created this file with the help of Google. My sample xml file is:
<?xml version="1.0"?>
<gamelist>
<game>
<title>Driver</title>
<code><EMBED src="http://www.pnflashgames.com/modules/pnFlashGames/games/racer.swf"></EMBED></code>
<rating>4</rating>
</game>
<game>
<title>ConeCrazy</title>
<code><EMBED src="http://www.pnflashgames.com/modules/pnFlashGames/games/ConeCrazy.swf"></EMBED></code>
<rating>3</rating>
</game>
</gamelist>
In the above file code element is having embed tag. For my application I need embed tag as a string. In code element if I use any string instead of embed tag I can read that string. If I use embed tag I am getting error like this:
[fatal error] gamelist.xml:5:103 : reference to entity "pn_uname" must end with the ";" delimeter .
I am using Java for reading xml file. In my Java class I want the whole embed tag as a string.
Upvotes: 1
Views: 1188
Reputation: 700362
To put html code as a value in an XML element you have to encode it:
<?xml version="1.0"?>
<gamelist>
<game>
<title>Driver</title>
<code><EMBED src="http://www.pnflashgames.com/modules/pnFlashGames/games/racer.swf"></EMBED></code>
<rating>4</rating>
</game>
<game>
<title>ConeCrazy</title>
<code><EMBED src="http://www.pnflashgames.com/modules/pnFlashGames/games/ConeCrazy.swf"></EMBED></code>
<rating>3</rating>
</game>
</gamelist>
List of: entities in XML
Upvotes: 4
Reputation: 338228
I suppose you are not generating the XML with suitable tools (a DOM API), but by concatenating strings.
If further suppose the XML you are showing in your question is not the one that triggers the error.
I think you have something like this:
<EMBED src="http://foo/bar/racer.swf?bla&pn_uname=baz"></EMBED>
This would trigger an error message stating that the character entity "pn_uname" is not well-formed.
The correct way to express the above would be:
<EMBED src="http://foo/bar/racer.swf?bla&pn_uname=baz"></EMBED>
...which is what using an API for XML generation would automatically handle for you. Avoid string concatenation to produce XML.
Upvotes: 5