Tuesday, May 01, 2012 8:23 PM
I have a form list/library in SharePoint, which consists of InfoPath forms, they are all in xml format.
Now, I need to go through all the xml files and retrieve some of its content. But I have no idea what code I have to write in order to get the xml document loaded onto. I have something like this, what should I do in the bolded section below?
PList formLibrary = newSite.AllWebs[strServerURL].Lists[libraryName];
SPListItemCollection collListItems = formLibrary.Items;
foreach (SPListItem oListItem in collListItems)
??? what should I do here ??? Where formXML will be the text of the file.
XmlDocument doc = new XmlDocument();
doc.InnerXml = formXML;
XmlNamespaceManager xNameSpace = InitNamespaceManager(doc);
XPathNavigator xNavMain = doc.CreateNavigator();
Thanks in advance, your help would be greatly appreciated.
Tuesday, May 01, 2012 8:31 PM
You can use XmlDocument.Load(formXML). After this you can use xpath queries to get child nodes. You can also use Xml.Linq and the XElement and XDocument classes.
Tuesday, May 01, 2012 10:08 PM
Actually, I would like to know how I can get the value of "formXML" out of the SP list, that is how can I load the string value to this variable formXML from a SP list/file,
formXML = loadString(SPlistitem.file.url) <-- something like this, what will be the method?
Wednesday, May 02, 2012 1:50 PM
I was able to get this working with the following code.
Stream fStream = oListItem.File.OpenBinaryStream() ;
byte MyData = new byte[fStream.Length];
fStream.Read(MyData, 0, (int)fStream.Length);
string formXML = Encoding.Unicode.GetString(MyData);
formXML = Encoding.UTF8.GetString(MyData);
- Marked As Answer by wkpli Wednesday, May 02, 2012 1:50 PM