Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the code is given below
C#
string m_URL = "http://www.ft.com/rss/home/us";
string xmlStr;
using (var wc = new WebClient())
{
    wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4");
    xmlStr = wc.DownloadString(m_URL);
}
         
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStr);

var bdata = XDocument.Load(xmlStr);


In the above code bdata the illegal charecters in path how to remove the illegal characters.


Illegal characters in path
Thanks in Advance...
Posted
Updated 8-Oct-15 1:39am
v5
Comments
Andreas Gieriet 8-Oct-15 5:46am    
Code block formatting added.
Andi
Andreas Gieriet 8-Oct-15 5:47am    
What are "illegal" characters?
What is the problem?
Regards
Andi
Athul MS 8-Oct-15 5:57am    
hi,Andreas Gieriet the code is changed pls and give me a solution
[no name] 8-Oct-15 6:04am    
Its working at our end. Document is loaded perfectly.
Athul MS 8-Oct-15 6:07am    
hi,
in bdata contains an error illegal charecters in path

In your case, you are fetching the data from a website, and using that as a "path" to a file.

So the illegal characters are part of the data you fetched from the site, and beyond our - or your - control.
The chances are that the data you have fetched is not a valid path at all - it's probably XML or HTML data.
So use the debugger, look at exactly what you are fecting and see what the data actually is. Then you can start deciding what is and isn't a "legal character" in your path.
 
Share this answer
 
Hi Athul,
XDocument Do not have any suitable method which can take whole xml string as input and load that xml. It have only method in which you have to pass URL of the source.

Please see the screen shot.

Screen Shot[^]
 
Share this answer
 
v2
Comments
Athul MS 8-Oct-15 6:45am    
is it possible to pass the URL source in Xdocument
[no name] 8-Oct-15 6:57am    
Yes you can pass URL("http://www.ft.com/rss/home/us") directly but you can not pass your header key
wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4");
So it will give you error like Unauthorized access or Forbidden.
C#
string illegal = "\"M\"\\a/ry/ h**ad:>> a\\/:*?\"| li*tt|le|| la\"mb.?";
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());

foreach (char c in invalid)
{
    illegal = illegal.Replace(c.ToString(), "");
}
 
Share this answer
 
Comments
Rakesh R Surve[RST] 8-Oct-15 6:11am    
Try this while it may helpful to you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900