I need to open and read an xml document from a web page which happens to be an InfoPath form. The form is on my PC. What is giving me fits being able to parse the nodes to get values. I'm not sure how to refer to the nodes to get the values. There is a lot
of documentation on connecting to SharePoint to do this, which is not an option. I've posted a sample of the XML from the InfoPath form to be able to read it and get the values into variables. At this point, I'm just trying to read the nodes ( need the elements
) in the document.
Here is my code. There is an error "There are multiple root elements." at the position "doc.Load(url);". Please make any suggestions.
If the code cannot open http://test/test.xml, I would get a error:" The remote server returned an error: (401) Unauthorized".
But there is an error "There are multiple root elements." at the position "doc.Load(url);". The error means the code should be open
http://test/test.xml?
Again, I tested you code against your xml - it returns "subject name", which is correct.
So, if you get an error on doc.Load() it either xml is different (not the one as per your example) or it cannot load http://test/test.xml, redirected to some other page and cannot open it.
You could do a quick test and read xml (and check if it is correct) and then load it to XmlDocument
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
... check here if strResult is correct xml
//doc.Load(url);
doc.LoadXml(strResult);
Member
1 Points
4 Posts
Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 17, 2015 11:22 AM|geminiiv|LINK
I need to open and read an xml document from a web page which happens to be an InfoPath form. The form is on my PC. What is giving me fits being able to parse the nodes to get values. I'm not sure how to refer to the nodes to get the values. There is a lot of documentation on connecting to SharePoint to do this, which is not an option. I've posted a sample of the XML from the InfoPath form to be able to read it and get the values into variables. At this point, I'm just trying to read the nodes ( need the elements ) in the document.
Here is my code. There is an error "There are multiple root elements." at the position "doc.Load(url);". Please make any suggestions.
test.xml:
All-Star
35149 Points
9075 Posts
Re: Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 17, 2015 11:39 AM|smirnov|LINK
I'm confused with what does "my PC" here means
If you want to access xml which is on client then that's not possible.
Or you mean you want to access remote xml from http://test/test.xml?
P.S. The code seems to be correct: https://dotnetfiddle.net/m3sytM
Output
subject name
Member
1 Points
4 Posts
Re: Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 17, 2015 02:04 PM|geminiiv|LINK
Yes. I want to access remote xml from http://test/test.xml
But I don't open your url: https://dotnetfiddle.net/m3sytM
Could you please insert the code to here? Thank you!
All-Star
35149 Points
9075 Posts
Re: Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 17, 2015 02:36 PM|smirnov|LINK
The code is exactly the same and it works.
It seems that your code cannot open http://test/test.xml and that's the reason you got an error.
Member
1 Points
4 Posts
Re: Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 17, 2015 11:30 PM|geminiiv|LINK
If the code cannot open http://test/test.xml, I would get a error:" The remote server returned an error: (401) Unauthorized".
But there is an error "There are multiple root elements." at the position "doc.Load(url);". The error means the code should be open http://test/test.xml?
All-Star
35149 Points
9075 Posts
Re: Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 18, 2015 08:00 AM|smirnov|LINK
Again, I tested you code against your xml - it returns "subject name", which is correct.
So, if you get an error on doc.Load() it either xml is different (not the one as per your example) or it cannot load http://test/test.xml, redirected to some other page and cannot open it.
You could do a quick test and read xml (and check if it is correct) and then load it to XmlDocument
Hope this helps.
Member
1 Points
4 Posts
Re: Reading and Parsing an InfoPath XML document on the SharePoint 2007
Mar 19, 2015 08:24 AM|geminiiv|LINK
Thank you very much.
The reason is SharePoint authority.
<div class="client_def_list"> <div class="client_def_list_item"> <div class="client_def_list_word_item"> <div class="client_def_list_word_content"> </div> </div> </div> </div>