CallConnection
asked on
parsing XML special characters in Javascript
Hello XML Experts!!
I am parsing XML webpage in javascript... The problem is that XML gets generated using hexadecimal notation for special charaters; for instance '+' is represented as "x002B", ' ' as "x0020" etc.
Can you please either:
a) Suggest the most efficient way to decode this? Please consider the fact that you may have several repeating characters in the string - "My (New) Brilliant C++ Total" would have 4 spaces and 2 pulsses and 2 different bracket characters.
b) Suggest C# (or VB) way to generate xml using .WriteXml() that would NOT generate hexadecimal characters?
B might get a bit tricky, but I think that B is MUCH, much better than A, because javascript might be quite slow to parse the output of a large page? I would also prefer C# if at all possible.
I am parsing XML webpage in javascript... The problem is that XML gets generated using hexadecimal notation for special charaters; for instance '+' is represented as "x002B", ' ' as "x0020" etc.
Can you please either:
a) Suggest the most efficient way to decode this? Please consider the fact that you may have several repeating characters in the string - "My (New) Brilliant C++ Total" would have 4 spaces and 2 pulsses and 2 different bracket characters.
b) Suggest C# (or VB) way to generate xml using .WriteXml() that would NOT generate hexadecimal characters?
B might get a bit tricky, but I think that B is MUCH, much better than A, because javascript might be quite slow to parse the output of a large page? I would also prefer C# if at all possible.
ASKER
Hi Andrew!!
Hmm.. No, I wasn't sure how..
I read the data from SQL then, I used the following to generate XML (in the "original" page):
...
myTable.TableName = "GetDetails";
myTable.WriteXml(Response. OutputStre am, System.Data.XmlWriteMode.I gnoreSchem a);
...
Is there a way to set it here?
Thanks!
Hmm.. No, I wasn't sure how..
I read the data from SQL then, I used the following to generate XML (in the "original" page):
...
myTable.TableName = "GetDetails";
myTable.WriteXml(Response.
...
Is there a way to set it here?
Thanks!
I think Andrew is right the XmlTextWriter can be constructed like this:
XmlTextWriter tw = new XmlTextWriter(path, System.Text.Encoding.UTF8) ;
Jim
XmlTextWriter tw = new XmlTextWriter(path, System.Text.Encoding.UTF8)
Jim
ASKER
Hi Jim,
I have seen this, however I am really looking for a web service approach, in which case I think I need to use WriteXml and Encoding is not one of the options as far as I could see (?)
Dmitri
I have seen this, however I am really looking for a web service approach, in which case I think I need to use WriteXml and Encoding is not one of the options as far as I could see (?)
Dmitri
ASKER
Hi, I suspect I might need to use something like:
using System.Xml.Serialization;
[...]
XmlSerializer xml = new XmlSerializer(typeof(DataT
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
xsn.Add(string.Empty, string.Empty);
xml.Serialize(Response.Out
//xml.Serialize(Response.O
- except the last line does quite not work if you add encoding to it... please help!
Dmitri
Sorry about the lag - had to go to a meeting. Is this the way you were extracting it from the data table; i.e. using serialize?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Jim,
Thank you, sounds very good - I will try this when I'm back at work!
Dmitri
Thank you, sounds very good - I will try this when I'm back at work!
Dmitri
Good luck.
Andrew