I have a code that reads Xml files and I have an InvoiceLine List that had Invoice lines in it. My question is, when I use SelectSingleNode and search for a spesific cbc:ID tag, it brings me the first cbc:ID tag in the DOCUMENT which is not inside my XmlElement. I am wondering how is that possible and how can I change my code so it only reads inside my element.Thanks.
XmlNodeList elemList = root.GetElementsByTagName("cac:InvoiceLine");
XmlNodeList SatirdakiIskontoList;
Logoveri.logo_satirsayisi = elemList.Count.ToString(); //faturadaki satır sayısı
XmlNode satirno1,urunadi,urunkodu,urunmiktari,uruntutari;
string satirno;
foreach (XmlElement e in elemList)
{
LOGOSatirVeri Logosatirveri = new LOGOSatirVeri();
// Logosatirveri = new LOGOSatirVeri();
Logosatirveri.logo_uuid = Logoveri.logo_uuid;
try
{
//MALZEME-HİZMET ADI
satirno = e.SelectSingleNode("//*[name()='cac:InvoiceLine']/*
[name()='cbc:ID']").InnerText;
Logosatirveri.logo_satirno = satirno;
}
}
It should bting me the ID of the line which goes as 1,2,3... but It brings me the Id of the whole Invoice which is outside my element.
Like Charleh indicated, it's the //
Change your "try" code to the following.