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

& char in XML document

P: n/a
cj
I'm receiving an xml formatted string that I pull data from by reading
it into an xml document like this:

Dim doc As New Xml.XmlDocument
doc.LoadXml(respstr)
Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name")
textbox1.text = co_name(0).innertext

Now I'm getting company names that have ampersands in them. I was not
aware that was not allowed in xml and had no method of dealing with it.
I can fix it like this:

textbox1.text = co_name(0).innertext.replace("&", "&")

But, is there another way?

I ask this question because someone showed me output they got from me
weeks ago and it had & in the company name instead of & How the
heck did it work back then? While the code is pretty much done now.
Back then it wasn't really even a program just a bunch of small groups
of code testing various ideas.
Apr 13 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
From what you've written it it rather confusing as to whether you are
recieving the 'bad' xml or whether you are sending the 'bad' xml. In one
sentence you say 'receiving' and in another you say 'got from me'.

If you are receiving the xml file from someone else and the xml is not
'well-formed' then return it to them for correction.

If you are building the xml file then using the XMLNode.InnerText = value
construct will ensure that any of the 5 'reserved' characters are handled
correctly.

By the way, the 5 reserved characters are < (&lt;) > (&gt) & (&amp;) '
(&apos;) and " (&quot).

If you are building the xml using string contenation then you will need to
replace the 'reserved' characters yourself.

"cj" <cj@nospam.nospam> wrote in message
news:O1****************@TK2MSFTNGP04.phx.gbl...
I'm receiving an xml formatted string that I pull data from by reading it
into an xml document like this:

Dim doc As New Xml.XmlDocument
doc.LoadXml(respstr)
Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name")
textbox1.text = co_name(0).innertext

Now I'm getting company names that have ampersands in them. I was not
aware that was not allowed in xml and had no method of dealing with it. I
can fix it like this:

textbox1.text = co_name(0).innertext.replace("&amp;", "&")

But, is there another way?

I ask this question because someone showed me output they got from me
weeks ago and it had & in the company name instead of &amp; How the heck
did it work back then? While the code is pretty much done now. Back then
it wasn't really even a program just a bunch of small groups of code
testing various ideas.

Apr 13 '06 #2

P: n/a
cj
I'm receiving the xml file, or probably better stated a string, via
internet connection from another company and It is well-formed for xml
as & is represented as &amp;. I have to take this data and give it to
folks here in a flat fixed width ascii file. So &amp; has to become &.

Now keep in mind they don't want the entire xml file just certain fields
so I pull the desired fields out, string them together and write them to
the ascii file.
Stephany Young wrote:
From what you've written it it rather confusing as to whether you are
recieving the 'bad' xml or whether you are sending the 'bad' xml. In one
sentence you say 'receiving' and in another you say 'got from me'.

If you are receiving the xml file from someone else and the xml is not
'well-formed' then return it to them for correction.

If you are building the xml file then using the XMLNode.InnerText = value
construct will ensure that any of the 5 'reserved' characters are handled
correctly.

By the way, the 5 reserved characters are < (&lt;) > (&gt) & (&amp;) '
(&apos;) and " (&quot).

If you are building the xml using string contenation then you will need to
replace the 'reserved' characters yourself.

"cj" <cj@nospam.nospam> wrote in message
news:O1****************@TK2MSFTNGP04.phx.gbl...
I'm receiving an xml formatted string that I pull data from by reading it
into an xml document like this:

Dim doc As New Xml.XmlDocument
doc.LoadXml(respstr)
Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name")
textbox1.text = co_name(0).innertext

Now I'm getting company names that have ampersands in them. I was not
aware that was not allowed in xml and had no method of dealing with it. I
can fix it like this:

textbox1.text = co_name(0).innertext.replace("&amp;", "&")

But, is there another way?

I ask this question because someone showed me output they got from me
weeks ago and it had & in the company name instead of &amp; How the heck
did it work back then? While the code is pretty much done now. Back then
it wasn't really even a program just a bunch of small groups of code
testing various ideas.


Apr 13 '06 #3

P: n/a
How are these special characters handled in XMLSerialization?

Apr 13 '06 #4

P: n/a
Using your code, with the addition of:

Dim respstr As String = "<docelement><co_name>abc &amp;
xyz</co_name></docelement>"

at the beginnning and:

Console.WriteLine(co_name(0).InnerText)

I get abc & xyz in both the textbox and displayed in the output window.

Therefore the incomming '&amp;' is correctly being converted to '&', so it
is difficult to understand exactly what your problem is.

w
"cj" <cj@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I'm receiving the xml file, or probably better stated a string, via
internet connection from another company and It is well-formed for xml as
& is represented as &amp;. I have to take this data and give it to folks
here in a flat fixed width ascii file. So &amp; has to become &.

Now keep in mind they don't want the entire xml file just certain fields
so I pull the desired fields out, string them together and write them to
the ascii file.
Stephany Young wrote:
From what you've written it it rather confusing as to whether you are
recieving the 'bad' xml or whether you are sending the 'bad' xml. In one
sentence you say 'receiving' and in another you say 'got from me'.

If you are receiving the xml file from someone else and the xml is not
'well-formed' then return it to them for correction.

If you are building the xml file then using the XMLNode.InnerText = value
construct will ensure that any of the 5 'reserved' characters are handled
correctly.

By the way, the 5 reserved characters are < (&lt;) > (&gt) & (&amp;) '
(&apos;) and " (&quot).

If you are building the xml using string contenation then you will need
to replace the 'reserved' characters yourself.

"cj" <cj@nospam.nospam> wrote in message
news:O1****************@TK2MSFTNGP04.phx.gbl...
I'm receiving an xml formatted string that I pull data from by reading
it into an xml document like this:

Dim doc As New Xml.XmlDocument
doc.LoadXml(respstr)
Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name")
textbox1.text = co_name(0).innertext

Now I'm getting company names that have ampersands in them. I was not
aware that was not allowed in xml and had no method of dealing with it.
I can fix it like this:

textbox1.text = co_name(0).innertext.replace("&amp;", "&")

But, is there another way?

I ask this question because someone showed me output they got from me
weeks ago and it had & in the company name instead of &amp; How the
heck did it work back then? While the code is pretty much done now.
Back then it wasn't really even a program just a bunch of small groups
of code testing various ideas.


Apr 13 '06 #5

P: n/a
Stephany,

I had to smile when I saw this.
From what you've written it it rather confusing as to whether you are
recieving ............................ In one sentence you say 'receiving'
..............
Sorry I could not resist to show it you because of the context from the
message and with no other meaning than the message was in.

Cor

If you are receiving the xml file from someone else and the xml is not
'well-formed' then return it to them for correction.

If you are building the xml file then using the XMLNode.InnerText = value
construct will ensure that any of the 5 'reserved' characters are handled
correctly.

By the way, the 5 reserved characters are < (&lt;) > (&gt) & (&amp;) '
(&apos;) and " (&quot).

If you are building the xml using string contenation then you will need to
replace the 'reserved' characters yourself.

"cj" <cj@nospam.nospam> wrote in message
news:O1****************@TK2MSFTNGP04.phx.gbl...
I'm receiving an xml formatted string that I pull data from by reading it
into an xml document like this:

Dim doc As New Xml.XmlDocument
doc.LoadXml(respstr)
Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name")
textbox1.text = co_name(0).innertext

Now I'm getting company names that have ampersands in them. I was not
aware that was not allowed in xml and had no method of dealing with it. I
can fix it like this:

textbox1.text = co_name(0).innertext.replace("&amp;", "&")

But, is there another way?

I ask this question because someone showed me output they got from me
weeks ago and it had & in the company name instead of &amp; How the heck
did it work back then? While the code is pretty much done now. Back then
it wasn't really even a program just a bunch of small groups of code
testing various ideas.


Apr 13 '06 #6

P: n/a
cj
Humm. I'll have to write that into a test app myself then try to
explain the differences between it (assuming it works for me) and what
I'm doing in my program. I'll have to get back to you. I'm swamped at
the moment so it might be awhile, or given the holiday it might be next
week. Anyway, thanks and I'll get back to you.

Stephany Young wrote:
Using your code, with the addition of:

Dim respstr As String = "<docelement><co_name>abc &amp;
xyz</co_name></docelement>"

at the beginnning and:

Console.WriteLine(co_name(0).InnerText)

I get abc & xyz in both the textbox and displayed in the output window.

Therefore the incomming '&amp;' is correctly being converted to '&', so it
is difficult to understand exactly what your problem is.

w
"cj" <cj@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I'm receiving the xml file, or probably better stated a string, via
internet connection from another company and It is well-formed for xml as
& is represented as &amp;. I have to take this data and give it to folks
here in a flat fixed width ascii file. So &amp; has to become &.

Now keep in mind they don't want the entire xml file just certain fields
so I pull the desired fields out, string them together and write them to
the ascii file.
Stephany Young wrote:
From what you've written it it rather confusing as to whether you are
recieving the 'bad' xml or whether you are sending the 'bad' xml. In one
sentence you say 'receiving' and in another you say 'got from me'.

If you are receiving the xml file from someone else and the xml is not
'well-formed' then return it to them for correction.

If you are building the xml file then using the XMLNode.InnerText = value
construct will ensure that any of the 5 'reserved' characters are handled
correctly.

By the way, the 5 reserved characters are < (&lt;) > (&gt) & (&amp;) '
(&apos;) and " (&quot).

If you are building the xml using string contenation then you will need
to replace the 'reserved' characters yourself.

"cj" <cj@nospam.nospam> wrote in message
news:O1****************@TK2MSFTNGP04.phx.gbl...
I'm receiving an xml formatted string that I pull data from by reading
it into an xml document like this:

Dim doc As New Xml.XmlDocument
doc.LoadXml(respstr)
Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name")
textbox1.text = co_name(0).innertext

Now I'm getting company names that have ampersands in them. I was not
aware that was not allowed in xml and had no method of dealing with it.
I can fix it like this:

textbox1.text = co_name(0).innertext.replace("&amp;", "&")

But, is there another way?

I ask this question because someone showed me output they got from me
weeks ago and it had & in the company name instead of &amp; How the
heck did it work back then? While the code is pretty much done now.
Back then it wasn't really even a program just a bunch of small groups
of code testing various ideas.

Apr 13 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.