XMLValidation Errors

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0in 0in 12pt <span style="font-size:10pt; color:#505050; line-height:115% Hi there,<br/>
<br/>
I have a complicated schema I am working on and I am getting the following validation errors when I validate in VB.NET. The same schema and xml got validated in XML Spy and Stylus studio:
<p style="margin-bottom:10pt <span style="font-size:10pt; color:#505050 The element credit-card in namespace http://www.xyz.com/data has invalid child element authorization-attempts in namespace http://www.xyz.com/data.
<p style="margin-bottom:10pt <span style="font-size:10pt; color:#505050 List of possible elements expected: authorization-attempts in namespace http://www.xyz.com/data.
<p style="margin-bottom:10pt <span style="font-size:10pt; color:#505050 The element XYZPaymentType in namespace âhttp://www.xyz.com/data has invalid child element number-of-days in namespace âhttp://www.xyz.com/data .
<p style="margin-bottom:10pt <span style="font-size:10pt; color:#505050 List of possible elements expected: number-of-days in namespace âhttp://www.xyz.com/data .
<p style="margin-bottom:10pt <span style="font-size:10pt; color:#505050 The element âABCPaymentTypeâ in namespace âhttp://www.xyz.com/data has invalid child element method-and-freq in namespace âhttp://www.xyz.com/data
.
<p style="margin-bottom:12pt <span style="font-size:10pt; color:#505050 List of possible elements expected: method-and-freq in namespace âhttp://www.xyz.com/dataâ<br/>
<span style="font-size:10pt; color:#505050 <br/>
The following four schema files are being used are:<br/>
mainschema.xsd / schema1.xsd / test-data.xsd / datatypes.xsd<br/>
<br/>
I have mocked up the schemas in order to explain the problem. The schemas i posted are just subset of what i have. This was the best I could do<br/>
<br/>
mainschema.xsd refers to schema1.xsd refers to test-data.xsd refers to datatypes.xsd<br/>
<br/>
I am using the following .NET code to validate:
<p style="margin-bottom:12pt <span style="font-size:10pt; color:blue Dim
<span style="font-size:10pt; color:#505050 xssInputXml <span style="font-size:10pt; color:blue As
<span style="font-size:10pt; color:blue New <span style="font-size:10pt; color:#505050
XmlSchemaSet<br/>
<span style="font-size:10pt; color:blue Dim <span style="font-size:10pt; color:#505050
strXmlSchemaPath <span style="font-size:10pt; color:blue As <span style="font-size:10pt; color:blue
String<br/>
Dim <span style="font-size:10pt; color:#505050 doc <span style="font-size:10pt; color:blue As
<span style="font-size:10pt; color:#505050 XmlDocument = <span style="font-size:10pt; color:blue New
<span style="font-size:10pt; color:#505050 XmlDocument()
<span style="font-size:10pt; color:#505050 strXmlSchemaPath = <span style="font-size:10pt; color:#a31515 "C:MainSchema.xsd"
<span style="font-size:10pt; color:#a31515 <br/>
xssInputXml.Add(" http://www.xyz.com/mainschema http://www.xyz.com/mainschema ", strXmlSchemaPath)<br/>
<br/>
<span style="font-size:10pt; color:#505050 doc.Schemas = xssInputXml<br/>
doc.Load( <span style="font-size:10pt; color:#a31515 "C:test.xml"
<span style="font-size:10pt; color:#505050 )<br/>
doc.Validate( <span style="font-size:10pt; color:blue AddressOf <span style="font-size:10pt; color:#505050
ValidationEventHandler2)
<span style="font-size:10pt; color:blue If <span style="font-size:10pt; color:#505050
sbValidationErrors.ToString() = <span style="font-size:10pt; color:blue String
<span style="font-size:10pt; color:#505050 .Empty <span style="font-size:10pt; color:blue Then<br/>
<span style="font-size:10pt; color:#505050 MsgBox( <span style="font-size:10pt; color:#a31515
"Validation is successful" <span style="font-size:10pt; color:#505050
+ sbValidationErrors.ToString())<br/>
<span style="font-size:10pt; color:blue Else<br/>
<span style="font-size:10pt; color:#505050 MsgBox( <span style="font-size:10pt; color:#a31515
"Validation Failed" <span style="font-size:10pt; color:#505050
+ sbValidationErrors.ToString())<br/>
<span style="font-size:10pt; color:blue End <span style="font-size:10pt; color:blue
If
<p style="margin:0in 0in 12pt <span style="font-size:10pt; color:#505050; line-height:115% <br/>
?xml version="1.0" encoding="UTF-8"?><br/>
<schema xmlns=" http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema "<br/>
targetNamespace=" http://www.xyz.com/mainschema http://www.xyz.com/mainschema "<br/>
xmlns:x=http://www.xyz.com/data<br/>
elementFormDefault="qualified" attributeFormDefault="unqualified <br/>
<br/>
<import namespace= http://www.xyz.com/data http://www.xyz.com/data schemaLocation="schema1.xsd"/><br/>
<br/>
<element name="mainschema <br/>
<complexType><br/>
<sequence><br/>
<element ref="x:application"/><br/>
</sequence><br/>
</complexType><br/>
</element><br/>
</schema><br/>
<br/>
schema1.xsd<br/>
<br/>
?xml version="1.0" encoding="UTF-8"?><br/>
<schema xmlns=" http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema "<br/>
targetNamespace=" http://www.xyz.com/mainschema http://www.xyz.com/mainschema "<br/>
xmlns:x=http://www.xyz.com/data<br/>
elementFormDefault="qualified" attributeFormDefault="unqualified <br/>
<br/>
<include schemaLocation="test-data.xsd"/><br/>
<br/>
<element name="application <br/>
<complexType><br/>
<sequence><br/>
<element name="test-data" type="x:TestData"/> <br/>
</element><br/>
</sequence><br/>
</complexType><br/>
</element><br/>
</schema><br/>
<br/>
<?xml version="1.0" encoding="UTF-8"?><br/>
<xs:schema xmlns:xs=" http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema " elementFormDefault="qualified" attributeFormDefault="unqualified <br/>
<xs:include schemaLocation="datatypes.xsd"/><br/>
<br/>
<xs:complexType name="TestData <br/>
<xs:sequence minOccurs="0 <br/>
<xs:element name="credit-card" type="CreditCardType" minOccurs="0"/><br/>
<xs:element name="bank-account" type="BankAccountType"/><br/>
<xs:element name="payment" type="PaymentType"/><br/>
<br/>
</xs:sequence><br/>
</xs:complexType><br/>
</xs:schema><br/>
<br/>
datatypes.xsd
<span style="font-size:10pt; color:#505050 <?xml version="1.0" encoding="UTF-8"?><br/>
<xs:schema xmlns:xs=" http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema "
<br/>
elementFormDefault="qualified" attributeFormDefault="unqualified <br/>
<br/>
<xs:complexType name="XYZPaymentType <br/>
<xs:sequence minOccurs="0 <br/>
<xs:element name="number-of-days"/><br/>
<xs:element name="method-and-period" type="xs:string"/><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<br/>
<xs:complexType name="ABCPaymentType <br/>
<xs:sequence minOccurs="0 <br/>
<xs:element name="frequency" type="xs:string"/><br/>
<xs:element name="method-and-freq"/><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<br/>
<xs:complexType name="PaymentType <br/>
<xs:sequence minOccurs="0 <br/>
<xs:element name="xyz-payment" type="XYZPaymentType"/><br/>
<xs:element name="abc-payment" type="ABCPaymentType"/><br/>
</xs:sequence><br/>
</xs:complexType>
<span style="font-size:10pt; color:#505050 <xs:complexType name="CreditCardType <br/>
<xs:sequence minOccurs="0 <br/>
<xs:element name="transaction-id" type="xs:string" minOccurs="0"/><br/>
<xs:element name="security-code" type="Numeric"/><br/>
<xs:element name="authorization-attempts" minOccurs="0 <br/>
<xs:complexType><br/>
<xs:attribute name="value"/><br/>
</xs:complexType><br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:complexType>
<span style="font-size:10pt; color:#505050 </xs:schema><br/>
<br/>
I have been struggling with this problem for weeks. Any help with this would be of great help. Thanks in advance.
<br/>
<br/>
Thanks

View the full article
 
Back
Top