473,385 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

& char in XML document

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
6 2223
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
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
How are these special characters handled in XMLSerialization?

Apr 13 '06 #4
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mali_djuro | last post by:
Hi all, i used JDOM to create XML file. first, i get data from database and create Document object. in some data i have quotas, so it makes replacment in content of elements. for example: if i...
1
by: Matt Garman | last post by:
Is there a generally accepted means of generating reports in C and/or C++? In particular, I have an application with many parameterized text strings that get displayed to a user. These could be...
28
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
16
by: Merrill & Michele | last post by:
The exercise is to remove all comments from a source file. What I've written so far is: /* decommentizer: removes this style of comment from source */ #include <stdio.h> void strconst(char);...
30
by: James Daughtry | last post by:
char array; scanf("%19s", &array); I know this is wrong because it's a type mismatch, where scanf expects a pointer to char and gets a pointer to an array of 20 char. I know that question 6.12...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.