Hi, everyone, I need to read a tons of xml files like this one:
<?xml version="1.0" encoding="UTF-8"?>
<IM>
<CR ID1="13" ID2="460">
</CR>
</IM>
my code in VBA is like:
For i = 1 To 100 'suppose i have 100 xml files
Filename = Sheet1.Cells(i, 1) 'where i store the file path
Set Doc = New DOMDocument
Set IM = Doc.DocumentElement
For Each CR In IM.ChildNodes
Set Attribute_CR = CR.Attributes
Set ID1 = Attribute_CR.getNamedItem("ID1")
Debug.Print ID1.Text
.....
Well, it works well. But my question is that, actually during some xml file, it doesnt always have ID1, (sometimes, they only have ID2 etc). So this code will not work for those files do not have ID1. But what should I to code it in general?
Thanks a lot
<?xml version="1.0" encoding="UTF-8"?>
<IM>
<CR ID1="13" ID2="460">
</CR>
</IM>
my code in VBA is like:
For i = 1 To 100 'suppose i have 100 xml files
Filename = Sheet1.Cells(i, 1) 'where i store the file path
Set Doc = New DOMDocument
Set IM = Doc.DocumentElement
For Each CR In IM.ChildNodes
Set Attribute_CR = CR.Attributes
Set ID1 = Attribute_CR.getNamedItem("ID1")
Debug.Print ID1.Text
.....
Well, it works well. But my question is that, actually during some xml file, it doesnt always have ID1, (sometimes, they only have ID2 etc). So this code will not work for those files do not have ID1. But what should I to code it in general?
Thanks a lot