24

I want to use & character but the Visual Studio throw exception. How Have to write this?

0

5 Answers 5

50

Replace any & with

&

It would load properly in XML.

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

Comments

13

You can use & or &, or you can wrap it in a CDATA section like this:

<![CDATA[Foo & Bar]]>

Comments

12

There are two ways to represent characters which have special meaning in XML (such as < and >) in an XML document.

  1. CDATA sections
  2. As entities

A CDATA section can only be used in places where you could have a text node.

<foo><![CDATA[Here is some data including < and > (and &!) ]]></foo>

The caveat is that you can't include the sequence ]]> as data in a CDATA section.

Entities can be used everywhere (except inside CDATA sections) and consist of &, then an identifier, then ;.

<foo>Here is some data including &lt; and &gt; (and &amp;!)</foo>

Comments

8

Use the entity, &amp;.

(+1 to the other answers that discuss CDATA.)

Comments

4

You may use a CDATA : Everything inside a CDATA section is ignored by the parser.

A CDATA section starts with <![CDATA[ and ends with ]]>

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.