473,785 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlTextReader.R eadString 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.R eadString() 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 2766
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****** **********@nosp am.com"
<David@Ce****** **********@nosp am.com@discussi ons.microsoft.c om> wrote in
message news:FF******** *************** ***********@mic rosoft.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.R eadString() 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******* *********@nospa m.com <David@CentralD evelopment> 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.R eadString() 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.co m>
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****** **********@nosp am.com"
<David@Ce****** **********@nosp am.com@discussi ons.microsoft.c om> wrote in
message news:FF******** *************** ***********@mic rosoft.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.R eadString() 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.co m>
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.co m>
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
3757
by: Hang Cheng | last post by:
I've been trying to parse the following XML file with the .NET XMLTextReader: <?xml version="1.0"?><level1><level2><level3>Test</level3><level3>Test2</level3></level2><level2><level3>Test</level3><level3>Test2</level3><level3><level4>TEST<level5>TEST5</level5>TESTP</level4><level4>Test4</level4></level3></level2></level1> However, the resulting output does not seem to make any sense: Start Element: level1 @ 0 Start Element: level2 @ 1...
5
9219
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 RelatedID="118"/> <PersonName> <NameTitle Value="Mr"/> <FirstName>Clint</FirstName> <OtherName/> <AlsoKnownAs>Mr C Eastwood</AlsoKnownAs>
1
16440
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
5457
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> <EmployeeStrength>> 1000</EmployeeStrength> When I do a Xmltextreader.read() and then check the contents of the xml node by XmltextReader.ReadString(), I get an exception when I have
3
6910
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 have a function that reads it as follows...
4
1703
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 have a very simple XML file that I wish to parse using Xmltextreader, but I seem to be having a lot of poblems with it. I have a subroutine that I pass a string into, and what I need to do is to find the element where that string exists, and then...
1
2711
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> <EmployeeStrength>> 1000</EmployeeStrength> When I do a Xmltextreader.read() and then check the contents of the xml node by XmltextReader.ReadString(), I get an exception when I have
5
364
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 into a string, the \x0095 are interpreted literally. However, the following code works fine: - string a = "\x0095 blah1 \x0095 blah2 \x0095 blah3 \x0095 blah4";
1
2470
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 debug the project, but when I publish the project and run it on a live server, I seem to be getting problems. I get the error:
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.