I have an XML document (an InfoPath form) that looks similar to this:
<my:ClientMaintenance xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-06T07:04:54">
<my:Payments>
</my:Payments>
<my:Payment>
<my:Amount></my:Amount>
<!-- Several other nodes -->
</my:Payment>
</my:ClientMaintenance>
The Payment
node is used as a template to add new payments to the Payments
node. So whenever the Add Payment button is clicked on the form, I need to:
- Take a copy of the
Payment
node in memory - Update the values
- Append it as a child to the
Payments
node
For some reason at the end of this, I can no longer query any nodes in the my
namespace! Here's the code:
public void btnAddPaymentClicked(object sender, ClickedEventArgs e)
{
var navigator = e.Source.CreateNavigator();
var blankPayment = GetBlankPaymentNode(navigator).CreateNavigator();
// new XmlNamespaceManager(blankPayment.NameTable).HasNamespace("my") == false
// WHY???
}
private XmlDocument GetBlankPaymentNode(XPathNavigator navigator)
{
var blankPayment = navigator.SelectSingleNode(FullBlankPaymentXPath, NamespaceManager);
var blankXml = new XmlDocument();
blankXml.LoadXml(blankPayment.OuterXml);
var schema = new XmlSchema();
schema.Namespaces.Add("my", MyNamespaceUri); // Set elsewhere and != null
blankXml.Schemas.Add(schema);
return blankXml;
}
Why can the namespace no longer be referenced?