1
I have an xml file with several structures. I have a structure called Product
who has a field ProductCode
and I have a structure called SalesInvoice
, inside of it I have a field Invoice
, within the Invoice
there’s another ProductCode
.
I have to compare the ProductCode
of the two structures. If they are equal I have to do one thing, if they are different I have to do something else.
It’s a little confusing but I explained the best I could, I hope you understand. I’m using C#!
What have you tried ?
– LP. Gonçalves
@LP.Gonçalves already tried to use Selectnodes, Selectsinglenode so that didn’t work needed a help, I’ve been in this situation for 1 week
– D C
You could update your question with this code snippet from which you tried to use Selectnodes, Selectsinglenode ?
– LP. Gonçalves
You need to learn the algorithms used to traverse a tree. Without that knowledge, even with the help of the people here it will be difficult to solve your problem.
– Oralista de Sistemas
@Renan I know how to use algorithms to go through a tree but I don’t know for a more complex situation like this
– D C
Until you update your question, it might help(it is in English) http://stackoverflow.com/questions/890313/how-to-use-a-linq-query-to-get-xelement-values-when-xelements-have-same-name
– LP. Gonçalves
In fact the situation you have is the simplest application of the pre-order, in-order, post-order algorithms etc. You need to go through a tree and find the productCode nodes and compare their values.
– Oralista de Sistemas
@Renan Exactly ! that’s right. The Productcode of the first structure (Product) I can get, I already have an algorithm to get it but I can’t get the other one (from the Salesinvoices structure). Compare them I think also with you, I just needed help to get it and maybe keep it in a variable to be easier
– D C
@Will Renan help me in this part of the algorithm ? I’ve been in it for 1 week and I can’t. It was really important
– D C
It would be better to post your code including XML because image becomes complicated to give a solution...
– novic
I already got what I wanted. Only now I have another problem. There are Productcodes with repeated values but I just want to get the first one, anyone know how? Here is my code: Xmlnodelist xnList = doc.Getelementsbytagname("Line"); foreach (Xmlnode Xn in xnList) { string salescode = Xn["Productcode"]. Innertext; if (salescode == code) { Console.Writeline(salescode); } Else; }
– D C