1) to pass the NodeList loop see through it that the namespace that you add is complete and the same as is in the file. Don't cut of.
2) Make sure you don't use one of the existing IEnumerables for XML.
- " "
- "xmlns"
- "xml"
add a specified one like I did, named "x". It will be added to the IEnumerable list.
Code is not working completely but we've passed the nodeList this time thanks to Jochen.
var doc = new XmlDocument();
string xml = richTextBox1.Text;
doc.LoadXml(xml);
XmlTextReader reader = new XmlTextReader(new StringReader(xml));
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(reader, System.Data.XmlReadMode.Auto);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("x", "un:unece:260:data:EEM:02-02-AnXMLTestFile");
var nodeList = doc.DocumentElement.SelectNodes("//x:HeaderBEDocument", nsmgr);
foreach (XmlNode node in nodeList)
{
var identificationNode = node.SelectSingleNode("x:Identification", nsmgr);
if (identificationNode != null)
{
identificationNode.InnerText = "string";
}
var SCI = node.SelectSingleNode("x:SCI", nsmgr);
if (SCI != null)
{
SCI.InnerText = "56987465";
}
var ReferenceType = node.SelectSingleNode("x:ReferenceType", nsmgr);
if (ReferenceType != null)
{
ReferenceType.InnerText = "AA";
}
var CCType = node.SelectSingleNode("x:CCType", nsmgr);
if (CCType != null)
{
CCType.InnerText = "string";
}
}
richTextBox1.Text = nodeList.ToString();
}