XML Schema Validations fails
I want to validate a load/build xml against a given schema. [VB]
Below there's the code, but when I (as in code) try to validate a wrong xml against the schema it also works.
Where's the bug??
Dim xd As MSXML2.DOMDocument50
Dim xs As MSXML2.XMLSchemaCache50
Set xs = CreateObject("Msxml2.XMLSchemaCache.5.0")
Set xd = CreateObject("Msxml2.DOMDocument.5.0")
xs.Add "http://www.w3.org/2001/XMLSchema", "C:\doit\schema.xsd"
Set xd.schemas = xs
xd.async = False
xd.validateOnParse = True
xd.resolveExternals = True
xd.Load "C:\doit\wrongOne.xml"
' xd.validate
If xd.parseError.errorCode <> 0 Then
MsgBox xd.parseError.reason
Else
msgbox xd.XML
End If
Set xs = Nothing
Set xd = Nothing
------
Schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="IN" type="Item"/>
<xsd:complexType name="Item">
<xsd:all>
<xsd:element name="A" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="B" type="xsd:buildIt" minOccurs="1" maxOccurs="1" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="buildIt">
<xsd:sequence>
<xsd:element name="C" type="xsd:string" minOccurs="1" maxOccurs="1" />
<xsd:element name="D" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
----
wanted xml:
<?xml version="1.0"?>
<IN xmlns="http://somewhere.org">
<A>today</A>
<B>
<C>myC</C>
<D>myD</D>
</B>
</IN>
wrong one (required B misses) used in code above:
<?xml version="1.0"?>
<IN xmlns="http://somewhere.org">
<A>today</A>
</IN>

