Link to home
Start Free TrialLog in
Avatar of CallConnection
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.
Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you set the encoding when you made your xml document?

Andrew
Avatar of CallConnection
CallConnection

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.OutputStream, System.Data.XmlWriteMode.IgnoreSchema);
  ...

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
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


Hi, I suspect I might need to use something like:

                using System.Xml.Serialization;
[...]
                XmlSerializer xml = new XmlSerializer(typeof(DataTable));
                XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
                xsn.Add(string.Empty, string.Empty);
                xml.Serialize(Response.OutputStream, dtRet, xsn);
                //xml.Serialize(Response.OutputStream, dtRet, xsn, "UTF8");
   - 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
Avatar of JimBrandley
JimBrandley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Jim,

Thank you, sounds very good - I will try this when I'm back at work!

Dmitri
Good luck.