PC Review


Reply
Thread Tools Rate Thread

Illegal Charaters in path

 
 
DBC User
Guest
Posts: n/a
 
      30th Aug 2006
Hi Claes,

I am getting this file from web. I am downloading this file using
webclient and how how it is adding 1 character before the actual file.
Stripping the first character solved the problem though. But why and
what is this first character?

Thanks.

Claes Bergefall wrote:
> "DBC User" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I have a small XML file, I uploaded to a web page. I have the following
> > code to convert the content I downloaded from web to xml and is giving
> > "Illegal characters in path", but when I try to see the value in XML
> > viewer (through add watch) and is showing the content correctly.
> >
> > Here is the code
> > ..
> > string b = wc.DownloadString(myurl);
> > XmlDocument doc = new XmlDocument();
> > doc.Load(str);
> > ....
> >
> > Could someone tell me what is wrong?

>
> XmlDocument.Load doesn't have an overlaod that loads XML from a string. The
> string overload expects a filename. Put your string in a StringReader and
> then load from that:
>
> XmlDocument doc = new XmlDocument();
> StringReader reader = new StringReader(b);
> doc.Load(reader);
>
>
> > When I change the Load to LoadXml I get 'Data at the root level is
> > invalid. Line 1, position 1"
> >
> > Here is the XML
> > <?xml version="1.0" encoding="utf-8" ?>
> > <Files>
> > <Application key="one">
> > <Version>1.0</Version>
> > </Application>
> > </Files>
> >

>
> LoadXml works with the above XML. Not sure why you get an error
>
> /claes


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      30th Aug 2006
Well, the binary looks like EF BB BF which is the UTF8 BOM; not sure why the
encoder isn't dealing with it, though...

Marc


 
Reply With Quote
 
 
 
 
Richard Whitcher
Guest
Posts: n/a
 
      30th Aug 2006
DBC,

> I am getting this file from web. I am downloading this file using
> webclient and how how it is adding 1 character before the actual file.
> Stripping the first character solved the problem though. But why and
> what is this first character?


You should be able to load the xml document without using the webclient:

....
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("http://www.someurl.com/file.xml");
....

That might solve the issue and with less code! ;o)

Regards,

Richard
--
Google First. Ask Later.
 
Reply With Quote
 
DBC User
Guest
Posts: n/a
 
      30th Aug 2006
Richard,
Your magic worked. It seems when I download the file using webclient
and then process I have the problem but if I load the xml directly from
the web, I do not have the problem.
Thanks again.
Richard Whitcher wrote:
> DBC,
>
> > I am getting this file from web. I am downloading this file using
> > webclient and how how it is adding 1 character before the actual file.
> > Stripping the first character solved the problem though. But why and
> > what is this first character?

>
> You should be able to load the xml document without using the webclient:
>
> ...
> XmlDocument xmlDoc = new XmlDocument();
> xmlDoc.Load("http://www.someurl.com/file.xml");
> ...
>
> That might solve the issue and with less code! ;o)
>
> Regards,
>
> Richard
> --
> Google First. Ask Later.


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      4th Sep 2006
Marc Gravell <(E-Mail Removed)> wrote:
> Well, the binary looks like EF BB BF which is the UTF8 BOM; not sure why the
> encoder isn't dealing with it, though...


The encoder is dealing with the BOM and decoding it to U+FEFF
correctly. XmlDocument.LoadXml doesn't appear to like that,
unfortunately. Either way, there's still the rogue 'X' though.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      4th Sep 2006
DBC User <(E-Mail Removed)> wrote:
> As I explained before. I have a simple XML
> (http://tamil.taisukina.com/ServerReferenceTest.xml) which has only
> one. I am able to view the xml on the web page. But when I use the
> following code, I am getting "Illegal charaters in path" message on
> doc.Load


That's because it's trying to use the XML data itself as a URL. That's
not the way to go.

> I changed the Load to LoadXml then I get bad root message.


Right - that's the correct call to make - the problem is that the file
is essentially corrupt.

> Here is the sample code where I can make the code fail.


Thanks.


Okay, let's look at this. Firstly, if you try to load the URL into
Firefox or IE, they both fail in the same way. That's a strong
suggestion that it's not the code that's wrong (when you've changed
Load to LoadXml) but the file.

The first two characters of the file are U+FFEF (which is the byte
order mark) and 'X'. Now, the byte order mark confuses
XmlDocument.LoadXml, which is debatable behaviour, but the presence of
the 'X' is very puzzling. It really just shouldn't be there.

You need to work out why the file is broken in terms of the 'X' to
start with, and then either use the overload given by Richard or
manually strip out the BOM.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      4th Sep 2006
The OP added this to allow the manual stripping by finding the first X and
adding one. Easy to miss in the signal : noise ratio of the chain though ;-p

Marc


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
illegal charaters George Hester Microsoft Windows 2000 3 21st Sep 2005 03:44 AM
MS says pirating is illegal, but are their PA rules illegal? PCyr Windows XP General 22 7th Aug 2003 04:45 AM
MS says pirating is illegal, but are their PA rules illegal? PCyr Windows XP Basics 19 7th Aug 2003 04:45 AM
MS says pirating is illegal, but are their PA rules illegal? PCyr Windows XP Security 17 7th Aug 2003 04:45 AM
MS says pirating is illegal, but are their PA rules illegal? PCyr Windows XP Help 17 7th Aug 2003 04:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.