1
I have the xml sequinte:
<det nItem="1">
<prod>
<cProd>01554</cProd>
<xProd>La Aslan Velour 0001 </xProd>
<NCM>55111000</NCM>
<CFOP>5102</CFOP>
<uCom>UN</uCom>
<qCom>1.0000</qCom>
<vUnCom>6.90</vUnCom>
<indRegra>A</indRegra>
</prod>
<imposto>
<ICMS>
<ICMSSN102>
<Orig>0</Orig>
<CSOSN>102</CSOSN>
</ICMSSN102>
</ICMS>
</imposto>
</det>
I have a loop that validates my products, it checks the taxes and return an error if the tax is incorrect. If a product happens to appear with the incorrect tax I need to know what it is, for this I use a counter in the loop, but how can I get the data of the item?
Items start with a <det nItem="1">
, what will change is the number that will indicate the item, but how can I point my counter to take the data that is inside the <det nItem="1">
?
Follow the code until then:
'Loop de todos os ICMS dos produtos
For Each ReadXML In document.Descendants("ICMS")
'Contador de produtos
Contador_Prod += 1
dim Prod = ReadXML.Descendants.Attributes(Contador_Prod)
Next
I thought I’d have to use the Attributes
, but it didn’t work out so well.
Have you tried this? http://stackoverflow.com/a/594243/221800 see other similar questions beside. Other http://stackoverflow.com/a/1431775/221800 If so, I can give you an answer.
– Maniero
So I didn’t get to see it, but it still doesn’t help, because the value between double quotes will be different for each item, but it will be sequential. It turns out I have to check the ICMS first and then the product if necessary. My idea was to use the counter to point, because in reality I need the contents of <Prod>
– Felipe S
Is that I don’t quite understand what you want but it’s a matter of giving a small adapted. Either you LINQ or any way to scan the XML directly.
– Maniero
So, after reading the ICMS, I have a function that checks if the ICMS is valid, if not, I need to identify in which XML product the ICMS is incorrect, but as I said the products have a sequence, which is determined by the nItem=" , ex: Product 1 = <det nItem="1">, product 2 = <det nItem="2"> If product 2 has the wrong ICMS, I need the <det nitem="2 data">
– Felipe S
Is there any possibility of me pointing out which nItem I need ? For example I have 10 items, I want item 6, how can I point to nItem="6" ? That would help me already.
– Felipe S
@Felipewalleg. Try to import as "a table", so you can use query and comparison command, looping and etc.
– Luiz Vichiatto