By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

xmldocument " and "

P: n/a
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;me@mydomain.com&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; <me@mydomain.com>"

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

Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Martin,

That's because the escaped entity is &quot; not &qout;

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"martin" <ma***************@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
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;me@mydomain.com&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; <me@mydomain.com>"

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

Nov 18 '05 #2

P: n/a
Try warpping the content in a CDATA block.

"martin" <ma***************@hotmail.com> wrote in message
news:Oo****************@TK2MSFTNGP12.phx.gbl...
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;me@mydomain.com&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; <me@mydomain.com>"

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

Nov 18 '05 #3

P: n/a
Also, &quot; is not a recognized entity in XML.

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Martin,

That's because the escaped entity is &quot; not &qout;

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"martin" <ma***************@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
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;me@mydomain.com&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; <me@mydomain.com>"
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


Nov 18 '05 #4

P: n/a
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;me@mydomain.com&gt;</Address>
</Addresses>

I am being to think that this is a bug.

any pointers are appreciated

cheers

martin


"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Martin,

That's because the escaped entity is &quot; not &qout;

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"martin" <ma***************@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
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;me@mydomain.com&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; <me@mydomain.com>"
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


Nov 18 '05 #5

P: n/a
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;me@mydomain.com&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.
Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.