14

So I have this XML doc:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <Item>
        <URL>http://www.mysite.com/page?id=1</URL>
    </Item>
</Root>

When I try and view the document, I get an error saying:

XML Parsing Error: not well-formed

at the = sign in the query string. I tried changing the = sign to %3D, but I get the same error at %

What am I supposed to do here?

1
  • Whatever XML parses claims that is isn't well formed, it's broken, because it is well formed. Try any online validator and they will all say the same thing "Well formed, no errors" Commented Dec 1, 2016 at 17:15

3 Answers 3

26

You can try <URL><![CDATA[http://www.example.com/page?id=1]]></URL>

All text in an XML document will be parsed by the parser. But text inside a CDATA section will be ignored by the parser. You can find more here.

Sign up to request clarification or add additional context in comments.

Comments

23

As you provide it, the XML is well formed. You don't have anything to escape in it. Maybe you have encoding problems in your source file. For information, the 2 characters you must escape in XML are :

& in &amp;
< in &lt;

Characters you may escape in attributes values (depending on the syntax you use for attributes : attr='value' or attr="value") :

" in &quot;
' in &apos;

Depending on the context, the last character that can be escaped :

> in &gt;

2 Comments

Why should CDATA be avoided?
@Adam: CDATA sections have drawbacks for several use cases such as nesting CDATA into CDATA (see here). That means that if you want to insert, for example, arbitrary XML in a CDATA section (I already encountered people who tried that), implementation is not straightforward.
4

try this <URL><![CDATA[http://www.mysite.com/page?id=1]]></URL>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.