Infopath Namespace manager creation code
I have had to create some code this week that reads the xml created by InfoPath. I then found that if you try and xpath on something you get a null return until the namespace manager has all of the correct entries. In the past I have created these manually but after a bit of google fo I have come up with the below piece of code. It takes an XMLDocument that you have created based on the form file (or any XML document really) and returns you a newly created namespace manager that can be used along side you xpath queries to get the data you want.
public static XmlNamespaceManager GetNameSpaceManager(XmlDocument xmlDoc) { XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable); foreach (XmlAttribute att in xmlDoc.DocumentElement.Attributes) { if (att.Prefix == "xmlns") { ns.AddNamespace(att.LocalName, att.Value); } } return ns; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
via Buzz Blog http://bit.ly/MuMAtl
Paul is a an expert SharePoint and Project Server developer and is responsible for designing and implementing custom solutions on client systems using the latest SharePoint and .NET technologies.
Paul has extensive experience with SharePoint systems across all sizes of implementation, ranging from small to large farms and has an excellent understanding of all the elements of SharePoint. This article has been cross posted from paulbuzzblog.wordpress.com (original article) |