+ Reply to Thread
Results 1 to 2 of 2

VBA excel load xml

  1. #1
    Registered User
    Join Date
    01-26-2005
    Posts
    3

    VBA excel load xml

    Hi,
    I need load xml file into excel via VBA code and validate this xml file with xsd template. I use Excel2002.
    My xsd template is :
    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="catalog" type="CatalogData"/>
    <xsd:complexType name="CatalogData">
    <xsd:sequence>
    <xsd:element name="book" type="bookdata" minOccurs="0"
    maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="bookdata">
    <xsd:sequence>
    <xsd:element name="author" type="xsd:string"/>
    <xsd:element name="title" type="xsd:string"/>
    <xsd:element name="genre" type="xsd:string"/>
    <xsd:element name="price" type="xsd:float"/>
    <xsd:element name="publish_date" type="xsd:date"/>
    <xsd:element name="description" type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string"/>
    </xsd:complexType>
    </xsd:schema>


    and my xml file is:
    <?xml version="1.0"?>
    <x:catalog xmlns:x="urn:books">
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications with
    XML.</description>
    <title>2000-10-01</title>
    </book>
    </x:catalog>

    and VBA code is:
    Sub loadXml()
    Dim xmlschema As Object
    Dim xmldom As Object

    Set xmldom = CreateObject("MSXML2.DOMDocument")
    xmldom.async = False
    Set xmlschema = CreateObject("MSXML2.XMLSchemaCache")
    xmlschema.Add "http://www.test.org", "c:\test.xsd"
    ...

    End Sub

    And I get an error in code:
    xmlschema.Add "http://www.test.org", "c:\test.xsd"

    The template contains bad definition in the root element. (It is only translation, because original error message is in Czech language.)

    I donīt know, where a problem is, because the template is valid (I check it in two validators.).

    Can anybody help me?
    Thanks
    Lenka

  2. #2
    Registered User
    Join Date
    01-26-2005
    Posts
    3

    I found an answer

    I found an answer my problem.

    When I create new MSXML2.DOMDocument, I define version of this object.

    Set xmldom = CreateObject("MSXML2.DOMDocument.5.0")
    xmldom.async = False
    Set xmlschema = CreateObject("MSXML2.XMLSchemaCache.5.0")

    The default version is 3 and this version canīt load xsd schema.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1