xmldocument " and "

  • Thread starter Thread starter martin
  • Start date Start date
M

martin

Hi,

I would be extremly grateful for some help on producing an xml fragemt.

The fragment that I wish to produce should look like this

<Addresses>
<Address>&qout;Somebody's Name&quot; &lt;[email protected]&gt;</Address>
</Addresses>

This looks simple enough however I am having great difficulty getting the
string "&quot;" to appear in the above fragment.
The & sign alway get escaped to &amp; so the line &quot; always appears as
&amp;quot; which is not what I require.
If I put in a " sign then the quote sign actually gets placed in the xml and
does not get escaped to &quot; at all.

any help is producing a fragment in the above format whould be greatly
appreciated.

cheers

martin.

PS. to demonstate what I mean I have included the code below that can be
run from a console application/

Imports System.IO

Imports System.Xml

Module Module1

Sub Main()

Dim xmlDoc As New XmlDocument

Dim xmlElemAddress As XmlNode

Dim root As XmlElement

Try

xmlDoc.LoadXml("<Addresses/>")

xmlElemAddress = xmlDoc.CreateNode(XmlNodeType.Element, "Address", "")

xmlElemAddress.InnerText = "&quot;Somebody's Name&quot; <[email protected]>"

root = xmlDoc.DocumentElement

root.AppendChild(xmlElemAddress)

xmlDoc.Save(Console.Out)

Catch ex As Exception

Console.WriteLine("***ERROR***")

Console.WriteLine(ex.Message.ToString())

Finally

End Try

End Sub
 
Hi rick,

this is the xml I want to be written. (I made a slight mistake in my
original posting. -- the first escaped " said &qout; which was incorrect.
the second one said &quot; -- which is correct.) The string I supplied in
the surce code that I supplied are correct.
make a new console application and paste it in, you will see what I mean.

This displays ok in IE however I can't write it out using xmldocument class
because the string &quot; always appears as &amp;quot;

<Addresses>
<Address>&quot;somebody's name&quot; &lt;[email protected]&gt;</Address>
</Addresses>

I am being to think that this is a bug.

any pointers are appreciated

cheers

martin
 
Hi peter
Also, &quot; is not a recognized entity in XML.

thats fair enough, but IE will display the follwoing xml document

<Addresses>
<Address>&quot;somebody's name&quot; &lt;[email protected]&gt;</Address>
</Addresses>

so it seems to me it is valid so I am stumped why I can't write "&quot;"
into the value of an element

also, I may be forced to use a CDATA section, although this is not what I
wanted to do.

cheers

martin.
 
Back
Top