473,322 Members | 1,473 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,322 software developers and data experts.

XmlTextReader.ReadString doesn't parse \x0095 character correctly

I have an xml file that, for example, contains the following element: -

<data>\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4</data>

If I use XmlTextReader.ReadString() to read this data into a string, the \x0095 are interpreted literally.

However, the following code works fine: -

string a = "\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4";

Can anyone please explain what I'm doing wrong? The point of all this is that \x0095 is a delimiter and I want to use the Split function to break the string up into an array, like this: -

string[] b = a.Split(new char[] {'\x0095'});

Thanks in advance.

David.


Jul 21 '05 #1
5 2732
the "\x" hex designator is C# syntax, not XML syntax.

To place Hex 95 into XML, you will need to use an XML code.
&#x0095;

However, I don't know if that character is valid in XML. You may need to
encode the entire string in Base64.

--- Nick

"David@Ce****************@nospam.com"
<David@Ce****************@nospam.com@discussions.m icrosoft.com> wrote in
message news:FF**********************************@microsof t.com...
I have an xml file that, for example, contains the following element: -

<data>\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4</data>

If I use XmlTextReader.ReadString() to read this data into a string, the \x0095 are interpreted literally.
However, the following code works fine: -

string a = "\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4";

Can anyone please explain what I'm doing wrong? The point of all this is that \x0095 is a delimiter and I want to use the Split function to break the
string up into an array, like this: -
string[] b = a.Split(new char[] {'\x0095'});

Thanks in advance.

David.

Jul 21 '05 #2
David@Ce****************@nospam.com <David@CentralDevelopment> wrote:
I have an xml file that, for example, contains the following element: -

<data>\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4</data>

If I use XmlTextReader.ReadString() to read this data into a string,
the \x0095 are interpreted literally.

However, the following code works fine: -

string a = "\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4";

Can anyone please explain what I'm doing wrong?


Sure - you're assuming that C# source code escape sequences and XML
escape sequences are the same. They're not.

If you want to include Unicode character 0x95 in your XML, use &#x95;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
Thanks Jon/Nick - that's very helpful. Unfortunately the xml file is being passed to me from another system, so I can't control what's in it. All I want to do is break this string into it's designated parts. Unless either of you have any other suggestions, I'll probably look at Regex.Split to see if that will allow me to split on a multi-character delimiter (although I've a feeling the backslash might complicate matters...).

Thanks again.

David.

"Nick Malik" wrote:
the "\x" hex designator is C# syntax, not XML syntax.

To place Hex 95 into XML, you will need to use an XML code.
•

However, I don't know if that character is valid in XML. You may need to
encode the entire string in Base64.

--- Nick

"David@Ce****************@nospam.com"
<David@Ce****************@nospam.com@discussions.m icrosoft.com> wrote in
message news:FF**********************************@microsof t.com...
I have an xml file that, for example, contains the following element: -

<data>\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4</data>

If I use XmlTextReader.ReadString() to read this data into a string, the

\x0095 are interpreted literally.

However, the following code works fine: -

string a = "\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4";

Can anyone please explain what I'm doing wrong? The point of all this is

that \x0095 is a delimiter and I want to use the Split function to break the
string up into an array, like this: -

string[] b = a.Split(new char[] {'\x0095'});

Thanks in advance.

David.


Jul 21 '05 #4
David <ce****************@nospam.com> wrote:
Thanks Jon/Nick - that's very helpful. Unfortunately the xml file is
being passed to me from another system, so I can't control what's in
it. All I want to do is break this string into it's designated parts.
Unless either of you have any other suggestions, I'll probably look
at Regex.Split to see if that will allow me to split on a
multi-character delimiter (although I've a feeling the backslash
might complicate matters...).


Backslash will complicate it, but shouldn't do so *that* much.

One option would be to convert the file first, turning \x0095 into
&#x95; everywhere, and *then* load it in.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
I went for the Regex.Split option in the end - it was quite straightforward, I just needed to escape the backslash. So, it was @"\\x0095".

"Jon Skeet [C# MVP]" wrote:
David <ce****************@nospam.com> wrote:
Thanks Jon/Nick - that's very helpful. Unfortunately the xml file is
being passed to me from another system, so I can't control what's in
it. All I want to do is break this string into it's designated parts.
Unless either of you have any other suggestions, I'll probably look
at Regex.Split to see if that will allow me to split on a
multi-character delimiter (although I've a feeling the backslash
might complicate matters...).


Backslash will complicate it, but shouldn't do so *that* much.

One option would be to convert the file first, turning \x0095 into
• everywhere, and *then* load it in.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hang Cheng | last post by:
I've been trying to parse the following XML file with the .NET XMLTextReader: <?xml...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
1
by: Emsi | last post by:
Hello, how can I read values of child nodes with the XmlTextReader? File format: <root> <items> <item> <field1>value1</field1> <field2>value2</field2>
1
by: RJN | last post by:
Hi I'm using XMLTextReader to parse the contents of XML. I have issues when the xml content itself has some special characters like & ,> etc. <CompanyName>Johnson & Jhonson</CompanyName>...
3
by: Willie B. Hardigan | last post by:
I have an XML file like so.. <?xml version="1.0" encoding="utf-8" ?> <zap> <data><string>abc</string><hex>a110ff</hex><rnd min="0" max="10"></rnd><string>xyz</string></data> </zap> and i...
4
by: Paul Bromley | last post by:
I thought that XMLTextReader would be simple to use, but I have run into problems with it! I seem to have great difficulty extrcting the text of specific elements from a very simple XML file. I...
1
by: RJN | last post by:
Hi I'm using XMLTextReader to parse the contents of XML. I have issues when the xml content itself has some special characters like & ,> etc. <CompanyName>Johnson & Jhonson</CompanyName>...
5
by: David | last post by:
I have an xml file that, for example, contains the following element: - <data>\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4</data> If I use XmlTextReader.ReadString() to read this data...
1
by: TheDude5B | last post by:
hi, I have a function which reads the xml from a web url into the XmlTextReader, and then I work my way through the reader producing html from the different nodes. All the code works fine when I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.