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
Bookmarks