473,385 Members | 1,320 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.

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 2735
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...
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...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.