[RESOLVED] Problem with read an XML file
Hello guys,
I wrote this code to read a xml
PHP Code:
Dim docXMLDOM As DOMDocument
Set docXMLDOM = New DOMDocument
docXMLDOM.Load "C:\Test\Test.xml"
MsgBox "The first element from the root has the following values: " & docXMLDOM.ChildNodes(1).FirstChild.Text
it works fine.
if the xml file looks like this
PHP Code:
<?xml version="1.0" encoding="utf-8" ?>
<Videos>
<Video>
<Title>The Distinguished Gentleman</Title>
<Director>Jonathan Lynn</Director>
<CastMembers>
<Actor>Eddie Murphy</Actor>
<Actor>Lane Smith</Actor>
<Actor>Sheryl Lee Ralph</Actor>
<Actor>Joe Don Baker</Actor>
<Actor>Victoria Rowell</Actor>
</CastMembers>
<Length>112 Minutes</Length>
<Format>DVD</Format>
<Rating>R</Rating>
</Video>
<Video>
<Title>Her Alibi</Title>
<Director>Bruce Beresford</Director>
<Length>94 Mins</Length>
<Format>DVD</Format>
<Rating>PG-13</Rating>
</Video>
<Video>
<Title>Chalte Chalte</Title>
<Director>Aziz Mirza</Director>
<Length>145 Mins</Length>
<Format>DVD</Format>
<Rating>N/R</Rating>
</Video>
</Videos>
the problem is.
I always recieving XML files they looks like this
see code below
PHP Code:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/3.0/style/exchange.xsl"?>
<ops:world-patent-data xmlns="http://www.xxxxxx.xxx/exchange" xmlns:ops="http://xxxx.xxxxx.org" xmlns:xlink="http://www.w3.org/1999/xlink">
<ops:meta name="elapsed-time" value="2"/>
<exchange-documents>
<exchange-document system="xxx.xxx.org" family-id="xxxx" country="xx" doc-number="xxxx" kind="A1">
<bibliographic-data>
<publication-reference>
<document-id document-id-type="docdb">
<country>xx</country>
<doc-number>xxxx</doc-number>
<kind>A1</kind>
<date>20120627</date>
</document-id>
<document-id document-id-type="xxx">
<doc-number>xxxx</doc-number>
<date>20120627</date>
</document-id>
Could someone help me to modify my code so it reads the first node?
I am not expeirenced in VBA DOM etc.
Thank you in advance people.
Re: Problem with read an XML file
You read it the same way... It will be this node here:
<ops:meta name="elapsed-time" value="2"/>
The reason youre code appears to fail is because the first node has no text ... it has two attributes, one cammed name and the other called value. if you look at the node object, you'll find an Attrobutes property which is a collection.
MsgBox "The first element from the root has the following values: " & docXMLDOM.ChildNodes(1).Attributes("name").Text (I think Text is right).
-tg
Re: Problem with read an XML file
Ok this is a way to complicated to me haha.
Could you help me to correct my code I should really appreciate that.
I tried this and it didn't work
see code below
PHP Code:
Dim docXMLDOM As DOMDocument
Set docXMLDOM = New DOMDocument
docXMLDOM.Load "C:\Test\Test.xml"
MsgBox "The first element from the root has the following values: " & docXMLDOM.ChildNodes(1).Attributes("name").Text
Thank you in advance