|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
& char in XML documentit 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. 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 < (<) > (>) & (&) ' (') and " ("). If you are building the xml using string contenation then you will need to replace the 'reserved' characters yourself. Show quoteHide quote "cj" <cj@nospam.nospam> wrote in message news:O12Y%235vXGHA.1204@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("&", "&") > > 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. 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 &. I have to take this data and give it to folks here in a flat fixed width ascii file. So & 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: Show quoteHide quote > 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 < (<) > (>) & (&) ' > (') and " ("). > > 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:O12Y%235vXGHA.1204@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("&", "&") >> >> 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. > > Using your code, with the addition of:
Dim respstr As String = "<docelement><co_name>abc & 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 '&' is correctly being converted to '&', so it is difficult to understand exactly what your problem is. w Show quoteHide quote "cj" <cj@nospam.nospam> wrote in message news:%23VKaFUwXGHA.1196@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 &. I have to take this data and give it to folks > here in a flat fixed width ascii file. So & 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 < (<) > (>) & (&) ' >> (') and " ("). >> >> 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:O12Y%235vXGHA.1204@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("&", "&") >>> >>> 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. >> 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: Show quoteHide quote > Using your code, with the addition of: > > Dim respstr As String = "<docelement><co_name>abc & > 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 '&' 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:%23VKaFUwXGHA.1196@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 &. I have to take this data and give it to folks >> here in a flat fixed width ascii file. So & 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 < (<) > (>) & (&) ' >>> (') and " ("). >>> >>> 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:O12Y%235vXGHA.1204@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("&", "&") >>>> >>>> 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. > Stephany,
I had to smile when I saw this. > From what you've written it it rather confusing as to whether you are Sorry I could not resist to show it you because of the context from the > recieving ............................ In one sentence you say 'receiving' > .............. message and with no other meaning than the message was in. Cor Show quoteHide quote > > 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 < (<) > (>) & (&) ' > (') and " ("). > > 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:O12Y%235vXGHA.1204@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("&", "&") >> >> 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. > >
Why does Replace return Nothing???
Should I use XML as a database for a standalone app? Mail attachment from memory Send email best use of vb.net and multithreading Determine if a File exists "Cross-thread operation not valid" without threading!! ComboBox in Bound DataGrid (VB 2003) Deleting INI file entry Why can't I get the right control height? |
|||||||||||||||||||||||