doc.SelectSingleNode("//my:Family", nsm).InnerText = "New Value";to have the desired effect. Alas, it’s not that simple. It never is, is it? Smile Instead, this is what you’re greeted with:
What we need to do is ensure that your XmlNamespaceManager is properly assigned with the content from the given InfoPath form in order to translate the “my:” part of our xPath statement. If we take a look at the InfoPath document’s OuterXml value we see this:With so many xmlns attributes in the InfoPath document, we need some automation to prepare our XmlNamespaceManager so we can interact with the data properly. Adding this little code snippet to our existing code, should resolve that nasty error:
foreach (XmlAttribute att in doc.DocumentElement.Attributes) { if (att.Prefix == "xmlns") { nsm.AddNamespace(att.LocalName, att.Value); } }
nsm = new XmlNamespaceManager(doc.NameTable);Throw all that together and we are now able to manipulate the InfoPath field programmatically to our heart’s content.
Cheers
C
No comments:
Post a Comment
Comments are moderated only for the purpose of keeping pesky spammers at bay.