2
I have a function that receives an xml file as a parameter.
public void lerXML(XmlDocument xmlDoc)
{
XmlNodeList xnCNPJ = xmlDoc.GetElementsByTagName("emit");
XmlNodeList xnNFE = xmlDoc.GetElementsByTagName("ide");
XmlNodeList xnChaveNFE = xmlDoc.GetElementsByTagName("infProt");
...
}
I want to apply this function to all files in a directory
In case, I’m doing so:
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(Diretorio);
foreach (FileInfo a in dirInfo.GetFiles())
{
lerXML(a.FullName);
}
However, the following error appears:
"Unable to convert from string to System.xml.Xmldocument"
I tried to leave it like this: lerXML(a);
but same mistake.
How could I accomplish this conversion?
Consider using
XDocument
instead ofXMLDocument
.– Augusto Vasques
what would be the difference between the two?
– Gabriel Henrique
XDocument
is much simpler to use and manipulate. It also has no flaw in the validation process (XSD) where in case of validation errors theXMLDocument
does not allow searching for the element or attribute that caused the validation error (although this facility has been documented in practice has not been implemented).– Augusto Vasques