tags:

views:

70

answers:

3

I'm writing an xml file. The file must contain the &q inside it and &y and &id. The problem is that when I'm opening the XML Viewer in Windows, it is giving me an error that semicolon is expected.

Is there any solution to this problem??? The element is:

<cs-uri-query> course=323-21-603&q=3&y=2002&id=671 </cs-uri-query>
+2  A: 

You must escape the & to include it in XML, using &amp;. Alternatively, you can store it in a CDATA section. Examples:

<element>course=323-21-603&amp;q=3</element>

<element><![CDATA[course=323-21-603&q=3]]></element>
David M
+1 for being technically right.
Tomalak
+4  A: 

"I'm writing an xml file."

No, you are not. You are writing a text file that you think looks like XML. Had you used an XML-aware tool to do it (i.e. a DOM API), you would not have asked this question, since the API would take care of these low-level problems.

There is an abundance of APIs, I'm sure there is one for your language of choice, too. To avoid this and a number of other subtle problems, I recommend you switch your code to using one.

Tomalak
+1 I may have been technically right, but I think this is a better answer!
David M
+1 Using an API for XML handling would sure be a more pragmatic approach.
missingfaktor
Well, Tomalak u are not perfectly correct about the API.when using the java API. I'm builting the Tags based on server raw data only.since some of tags also contain ( and ) and it gives a run time error.Is there any reason for such error??
Mew 3.2
Post the Java code that gives you the error and I can show you what you're doing wrong.
Tomalak
well, the code is around 200 lines: here is the link::~http://pastebin.com/m18cd9048In this all the tags are present early .The tag's line starts with#Fields.just check the code...
Mew 3.2
what u actually need is present at line 88
Mew 3.2
Will be looking at the code, I come back to you later. What does Data.txt contain?
Tomalak
+3  A: 

There are some characters that are reserved in XML. Ampersand is one of them. For displaying such characters, you need to use entity references.

Some commonly used entity references are as follows :

alt text

As can be seen in above table, entity reference for ampersand is &amp; .

missingfaktor
Serge - appTranslator
The only entities defined *by name* for XML are `<`, `>`, ``. The others you name here will trigger errors in a normal XML file.
Tomalak
@Tomalak : Corrected it.
missingfaktor