Results 1 to 3 of 3

Thread: [RESOLVED] Problem with read an XML file

  1. #1

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    Resolved [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.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member elmnas's Avatar
    Join Date
    Jul 2009
    Posts
    127

    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
    Last edited by elmnas; Aug 21st, 2014 at 03:41 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width