I need to work with xml files coming directly from URL. Viewing the xml file (url) works well in FireFox, but the root element is not shown in the browser. It does show when I click view source. That is: <?xml version="1.0" encoding="ISO-8859-1"?>
So my question is, how can I read that xml directly from url?
I get "...is an unexpected token. The expected token is '='." as error because of that missing line...
Can I add the <?xml version="1.0" encoding="ISO-8859-1"?> in some way? It doesn't matter if I have to create a temporary file... Any suggestions are welcome.. I'm stuck :|
Validation Complete
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!
string uri = " http://localhost:1589/doc.xml";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "GET";
req.MaximumAutomaticRedirections = 3;
req.Timeout = 50000;
Console.WriteLine("Sending HTTP request");
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Stream resst = res.GetResponseStream();
StreamReader sr = new StreamReader(resst);
Console.WriteLine("HTTP Response is: ");
XmlDocument doc = new XmlDocument();
doc.LoadXml(sr.ReadToEnd());
sr.Close();
resst.Close();
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
underlined are the things I dunno how to translate (that still show as error):
Dim uri As String = " http://localhost:1589/doc.xml" Dim req As System.Net.HttpWebRequest = HttpWebRequest.WebRequest.Create(uri)
req.Method = "GET"
req.MaximumAutomaticRedirections = 3
req.Timeout = 50000
Console.WriteLine("Sending HTTP request")
dim res as HttpWebResponse = (HttpWebResponse)req.GetResponse() Dim resst As stream = res.GetResponseStream() Dim sr As System.IO.StreamReader = New StreamReader(resst)
Console.WriteLine("HTTP Response is: ")
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(sr.ReadToEnd())
sr.Close()
resst.Close()
Validation Complete
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!
Dim uri As String = " http://localhost:1589/doc.xml"
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(uri), HttpWebRequest)
req.Method = "GET"
req.MaximumAutomaticRedirections = 3
req.Timeout = 50000
Console.WriteLine("Sending HTTP request")
Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim resst As Stream = res.GetResponseStream()
Dim sr As New StreamReader(resst)
Console.WriteLine("HTTP Response is: ")
Dim doc As New XmlDocument()
doc.LoadXml(sr.ReadToEnd())
sr.Close()
resst.Close()
Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
My issue was not even related to an invalid XML file, but the URL that was supposed to retrieve the XML was doing a quick login check (redirects), and I was actually not even reading the XML file.
So, thanks for those who tried to help me, and I will go hide in the shadows of shame.[:$]
(So the "ALIGN" error was probably coming from reading HTML with an align= attribute)
Validation Complete
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!
NNM
Participant
1414 Points
559 Posts
how to read/fix an invalid xml file?
Mar 03, 2008 06:20 AM|LINK
Hello,
I need to work with xml files coming directly from URL. Viewing the xml file (url) works well in FireFox, but the root element is not shown in the browser. It does show when I click view source. That is: <?xml version="1.0" encoding="ISO-8859-1"?>
So my question is, how can I read that xml directly from url?
I get "...is an unexpected token. The expected token is '='." as error because of that missing line...
Can I add the <?xml version="1.0" encoding="ISO-8859-1"?> in some way? It doesn't matter if I have to create a temporary file... Any suggestions are welcome.. I'm stuck :|
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: how to read/fix an invalid xml file?
Mar 04, 2008 05:14 AM|LINK
Hi NNM ,
Try this.
string uri = " http://localhost:1589/doc.xml"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.Method = "GET"; req.MaximumAutomaticRedirections = 3; req.Timeout = 50000; Console.WriteLine("Sending HTTP request"); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); Stream resst = res.GetResponseStream(); StreamReader sr = new StreamReader(resst); Console.WriteLine("HTTP Response is: "); XmlDocument doc = new XmlDocument(); doc.LoadXml(sr.ReadToEnd()); sr.Close(); resst.Close();Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
NNM
Participant
1414 Points
559 Posts
Re: how to read/fix an invalid xml file?
Mar 10, 2008 06:35 AM|LINK
I forgot to mention I use vb.net... :s
Here's what I have so far for vb:
underlined are the things I dunno how to translate (that still show as error):
Dim uri As String = " http://localhost:1589/doc.xml"
Dim req As System.Net.HttpWebRequest = HttpWebRequest.WebRequest.Create(uri)
req.Method = "GET"
req.MaximumAutomaticRedirections = 3
req.Timeout = 50000
Console.WriteLine("Sending HTTP request")
dim res as HttpWebResponse = (HttpWebResponse)req.GetResponse()
Dim resst As stream = res.GetResponseStream()
Dim sr As System.IO.StreamReader = New StreamReader(resst)
Console.WriteLine("HTTP Response is: ")
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(sr.ReadToEnd())
sr.Close()
resst.Close()
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!
Samu Zhang -...
All-Star
62163 Points
6101 Posts
Re: how to read/fix an invalid xml file?
Mar 10, 2008 07:29 AM|LINK
Hi ,
Dim uri As String = " http://localhost:1589/doc.xml" Dim req As HttpWebRequest = DirectCast(WebRequest.Create(uri), HttpWebRequest) req.Method = "GET" req.MaximumAutomaticRedirections = 3 req.Timeout = 50000 Console.WriteLine("Sending HTTP request") Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse) Dim resst As Stream = res.GetResponseStream() Dim sr As New StreamReader(resst) Console.WriteLine("HTTP Response is: ") Dim doc As New XmlDocument() doc.LoadXml(sr.ReadToEnd()) sr.Close() resst.Close()Samu Zhang
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
NNM
Participant
1414 Points
559 Posts
Re: how to read/fix an invalid xml file?
Mar 10, 2008 07:46 AM|LINK
Hello, thanx for the code,
but I get the exact same error as before, this time on this line:
'ALIGN' is an unexpected token. The expected token is '='. Line 44, position 12.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!
adman666
Member
468 Points
71 Posts
Re: how to read/fix an invalid xml file?
Apr 16, 2008 01:47 AM|LINK
Did you try using doc.Load(sr.ReadToEnd())
Thanks.
NNM
Participant
1414 Points
559 Posts
Re: how to read/fix an invalid xml file?
Apr 16, 2008 07:18 AM|LINK
My issue was not even related to an invalid XML file, but the URL that was supposed to retrieve the XML was doing a quick login check (redirects), and I was actually not even reading the XML file.
So, thanks for those who tried to help me, and I will go hide in the shadows of shame.[:$]
(So the "ALIGN" error was probably coming from reading HTML with an align= attribute)
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I'll always mark your post(s) as answer when it is!