Connecting Tech Pros Worldwide Forums | Help | Site Map

Illegal Charaters in path

DBC User
Guest
 
Posts: n/a
#1: Aug 29 '06
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?
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>


Cor Ligthert [MVP]
Guest
 
Posts: n/a
#2: Aug 30 '06

re: Illegal Charaters in path


Hi,

You are sure that you start your strings with @?

(we don't see anything from your string that is not accepted)

Cor

"DBC User" <dbcuser@gmail.comschreef in bericht
news:1156884340.080076.56420@m73g2000cwd.googlegro ups.com...
Quote:
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?
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>
>

Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#3: Aug 30 '06

re: Illegal Charaters in path


DBC User <dbcuser@gmail.comwrote:
Quote:
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.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
DBC User
Guest
 
Posts: n/a
#4: Aug 30 '06

re: Illegal Charaters in path


Hi Jon,

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, I changed the Load to LoadXml then I get bad root message.
Here is the sample code where I can make the code fail.


using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;

namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
doc.Load(b);
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}


}
}
}

Thanks for your time.


Jon wrote:
Quote:
DBC User <dbcuser@gmail.comwrote:
Quote:
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.
>
Could you post a short but complete program which demonstrates the
problem?
>
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
>
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
DBC User
Guest
 
Posts: n/a
#5: Aug 30 '06

re: Illegal Charaters in path


In the sample code I used the LoadXml first and got Data at the root
level is invalid. Line 1, position 1. Then I tried load, well I
shouldn't since it is for the loading of xml file :) But I still have
the root level in valid message.
So please read doc.Load as doc.LoadXml(b)

Thanks.

DBC User wrote:
Quote:
Hi Jon,
>
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, I changed the Load to LoadXml then I get bad root message.
Here is the sample code where I can make the code fail.
>
>
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;
>
namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
doc.Load(b);
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}
>
>
}
}
}
>
Thanks for your time.
>
>
Jon wrote:
Quote:
DBC User <dbcuser@gmail.comwrote:
Quote:
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.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
DBC User
Guest
 
Posts: n/a
#6: Aug 30 '06

re: Illegal Charaters in path


One more odd thing I noticed is when I debugged the code and checked
the value in text mode, I see a space betweeb < and Files. Even though
the file doesn't have the space nor the the string have the space.
Where is this space coming from?
Thanks.
DBC User wrote:
Quote:
In the sample code I used the LoadXml first and got Data at the root
level is invalid. Line 1, position 1. Then I tried load, well I
shouldn't since it is for the loading of xml file :) But I still have
the root level in valid message.
So please read doc.Load as doc.LoadXml(b)
>
Thanks.
>
DBC User wrote:
Quote:
Hi Jon,

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, I changed the Load to LoadXml then I get bad root message.
Here is the sample code where I can make the code fail.


using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;

namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
doc.Load(b);
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}


}
}
}

Thanks for your time.


Jon wrote:
Quote:
DBC User <dbcuser@gmail.comwrote:
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.
>
Could you post a short but complete program which demonstrates the
problem?
>
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
>
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
DBC User
Guest
 
Posts: n/a
#7: Aug 30 '06

re: Illegal Charaters in path


All,

I modified the XML file and added first letter as X before the root.
The modified the code to find X and then copy everything after X and
try loading the XML and it worked. But what is the first character that
is causing the problem? Following code with the change to XML worked.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;

namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
int start = b.IndexOf('X')+1;
string t = b.Substring(start, b.Length-start);
doc.LoadXml(t);
}
catch (XmlException e1)
{
string t = e1.ToString();
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}


}
}
}

DBC User wrote:
Quote:
One more odd thing I noticed is when I debugged the code and checked
the value in text mode, I see a space betweeb < and Files. Even though
the file doesn't have the space nor the the string have the space.
Where is this space coming from?
Thanks.
DBC User wrote:
Quote:
In the sample code I used the LoadXml first and got Data at the root
level is invalid. Line 1, position 1. Then I tried load, well I
shouldn't since it is for the loading of xml file :) But I still have
the root level in valid message.
So please read doc.Load as doc.LoadXml(b)

Thanks.

DBC User wrote:
Quote:
Hi Jon,
>
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, I changed the Load to LoadXml then I get bad root message.
Here is the sample code where I can make the code fail.
>
>
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;
>
namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
doc.Load(b);
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}
>
>
}
}
}
>
Thanks for your time.
>
>
Jon wrote:
DBC User <dbcuser@gmail.comwrote:
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.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Cor Ligthert [MVP]
Guest
 
Posts: n/a
#8: Aug 30 '06

re: Illegal Charaters in path


DBC user,

Did you look at my reply as well.

I see you use a double // and a single / in your Url path.

In my idea should that give an "Illegal charachter in path"

What was the problem that you had?

Cor

"DBC User" <dbcuser@gmail.comschreef in bericht
news:1156948869.005751.285400@h48g2000cwc.googlegr oups.com...
Quote:
One more odd thing I noticed is when I debugged the code and checked
the value in text mode, I see a space betweeb < and Files. Even though
the file doesn't have the space nor the the string have the space.
Where is this space coming from?
Thanks.
DBC User wrote:
Quote:
>In the sample code I used the LoadXml first and got Data at the root
>level is invalid. Line 1, position 1. Then I tried load, well I
>shouldn't since it is for the loading of xml file :) But I still have
>the root level in valid message.
>So please read doc.Load as doc.LoadXml(b)
>>
>Thanks.
>>
>DBC User wrote:
Quote:
Hi Jon,
>
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, I changed the Load to LoadXml then I get bad root message.
Here is the sample code where I can make the code fail.
>
>
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;
>
namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
doc.Load(b);
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}
>
>
}
}
}
>
Thanks for your time.
>
>
Jon wrote:
DBC User <dbcuser@gmail.comwrote:
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.
>
Could you post a short but complete program which demonstrates the
problem?
>
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
>
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
>

DBC User
Guest
 
Posts: n/a
#9: Aug 30 '06

re: Illegal Charaters in path


The first letter that is coming from the XML is invalid I tried to
pharse the first letter to char and got a 62345 number and character is
'' so I dropped the first character and everything worked fine. But I
am trying to find out how come I got this weired character in the
begining.
Thanks.

Cor Ligthert [MVP] wrote:
Quote:
DBC user,
>
Did you look at my reply as well.
>
I see you use a double // and a single / in your Url path.
>
In my idea should that give an "Illegal charachter in path"
>
What was the problem that you had?
>
Cor
>
"DBC User" <dbcuser@gmail.comschreef in bericht
news:1156948869.005751.285400@h48g2000cwc.googlegr oups.com...
Quote:
One more odd thing I noticed is when I debugged the code and checked
the value in text mode, I see a space betweeb < and Files. Even though
the file doesn't have the space nor the the string have the space.
Where is this space coming from?
Thanks.
DBC User wrote:
Quote:
In the sample code I used the LoadXml first and got Data at the root
level is invalid. Line 1, position 1. Then I tried load, well I
shouldn't since it is for the loading of xml file :) But I still have
the root level in valid message.
So please read doc.Load as doc.LoadXml(b)
>
Thanks.
>
DBC User wrote:
Hi Jon,

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, I changed the Load to LoadXml then I get bad root message.
Here is the sample code where I can make the code fail.


using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Collections;

namespace xmlreadproblem
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string b =
wc.DownloadString("http://tamil.taisukina.com/ServerReferenceTest.xml");
wc.Dispose();
XmlDocument doc = new XmlDocument();
doc.Load(b);
}
catch (Exception e1)
{
string t = e1.ToString();
//TODO: Make exception more specific
}


}
}
}

Thanks for your time.


Jon wrote:
DBC User <dbcuser@gmail.comwrote:
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.
>
Could you post a short but complete program which demonstrates the
problem?
>
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
>
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Claes Bergefall
Guest
 
Posts: n/a
#10: Aug 30 '06

re: Illegal Charaters in path


"DBC User" <dbcuser@gmail.comwrote in message
news:1156884340.080076.56420@m73g2000cwd.googlegro ups.com...
Quote:
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);

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


DBC User
Guest
 
Posts: n/a
#11: Aug 30 '06

re: Illegal Charaters in path


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:
Quote:
"DBC User" <dbcuser@gmail.comwrote in message
news:1156884340.080076.56420@m73g2000cwd.googlegro ups.com...
Quote:
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);
>
>
Quote:
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
Marc Gravell
Guest
 
Posts: n/a
#12: Aug 30 '06

re: Illegal Charaters in path


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


Richard Whitcher
Guest
 
Posts: n/a
#13: Aug 30 '06

re: Illegal Charaters in path


DBC,
Quote:
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.
DBC User
Guest
 
Posts: n/a
#14: Aug 30 '06

re: Illegal Charaters in path


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:
Quote:
DBC,
>
Quote:
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.
Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#15: Sep 4 '06

re: Illegal Charaters in path


DBC User <dbcuser@gmail.comwrote:
Quote:
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.
Quote:
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.
Quote:
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 - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#16: Sep 4 '06

re: Illegal Charaters in path


Marc Gravell <marc.gravell@gmail.comwrote:
Quote:
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 - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Marc Gravell
Guest
 
Posts: n/a
#17: Sep 4 '06

re: Illegal Charaters in path


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


Closed Thread


Similar C# / C Sharp bytes