Can't Parse XML data with C# [Nightmare]



i have been trying to extract one value from a XML file, and then store it on the same file but in another node, i tried all the examples i've found on the net, read XPath Syntax documentation like hell and still can't get it to work.


I must take the ID Value (which may vary) and copy it into .


But i can't even do that if i can't manage to parse the lines, most of times node/variables/"", or i get an "object reference not stablished as object instance error".


Here's the code:



// Create a new XML document.
XmlDocument xmlDoc = new XmlDocument();
// Load an XML file into the XmlDocument object.
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(pfile);

//TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PROBLEMA

XmlNodeList Documentos = xmlDoc.GetElementsByTagName("//Documento");
XmlNodeList DatosDocumento = ((XmlElement)Documentos[0]).GetElementsByTagName("ID");

foreach (XmlElement nodo in DatosDocumento)
{

int i = 0;

XmlNodeList ID = nodo.GetElementsByTagName("ID");
Console.WriteLine("Elemento nombre ... {0}}", ID[i].InnerText);

}

//
XmlNodeList nodes = xmlDoc.SelectNodes("EnvioDTE");
XmlNode nodesimple = xmlDoc.SelectSingleNode("EnvioDTE");
Console.WriteLine("Lista Nodos: " + nodes.Count);
Console.WriteLine("Nodo Simple: " + nodesimple.InnerText);
foreach (XmlNode node in nodes)
{
string id = node.Attributes["ID"].InnerText;
Console.WriteLine(id);

}


I am almost certain the problem is on the XPath Syntax, but i can't get it to work.


sadly i can't use XDocument as im using .NET 3.5 for this task, i would really appreciate some help on this, by behand apologize my bad english


As the XML file is too big, il put it here on this URL http://ift.tt/1qX36yB


Thanks in advance


No comments:

Post a Comment