469,352 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

how to validate xml file against xsd file in vb6

I m trying to validating xml file against xsd file in vb6.0
but i m getting an error

xsd file:(Aces_Dlr.xsd)

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--W3C Schema generated by XMLSpy v2010 (http://www.altova.com)-->
  3. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4.        xmlns:n="urn:sample"
  5.        targetNamespace="urn:sample">
  6.  
  7.     <xs:attribute name="ToolVer">
  8.         <xs:simpleType>
  9.             <xs:restriction base="xs:decimal">
  10.                 <xs:enumeration value="1.0"/>
  11.             </xs:restriction>
  12.         </xs:simpleType>
  13.     </xs:attribute>
  14.     <xs:simpleType name="ST_QUANTITY">
  15.         <xs:restriction base="xs:decimal">
  16.             <xs:maxInclusive value="999999999999.99"/>
  17.             <xs:pattern value="[0-9]{0,12}(.)[0-9]{0,2}"/>
  18.         </xs:restriction>
  19.     </xs:simpleType>
  20.     <xs:simpleType name="ST_AMOUNT-OF-DUTY-INVOLVED">
  21.         <xs:restriction base="xs:decimal">
  22.             <xs:maxInclusive value="9999999999999.00"/>
  23.             <xs:pattern value="[0-9]{0,13}(.)[0]{0,2}"/>
  24.         </xs:restriction>
  25.     </xs:simpleType>
  26.     <xs:attribute name="SL-NO">
  27.         <xs:simpleType>
  28.             <xs:restriction base="xs:string">
  29.                 <xs:pattern value="[0-9]{1,4}"/>
  30.             </xs:restriction>
  31.         </xs:simpleType>
  32.     </xs:attribute>
  33.     <xs:attribute name="ReturnType">
  34.         <xs:simpleType>
  35.             <xs:restriction base="xs:string">
  36.                 <xs:enumeration value="DLR"/>
  37.             </xs:restriction>
  38.         </xs:simpleType>
  39.     </xs:attribute>
  40.     <xs:element name="SELF-ASSESSMENT-MEMORANDAM">
  41.         <xs:complexType>
  42.             <xs:sequence>
  43.                 <xs:element ref="DATE"/>
  44.                 <xs:element ref="PLACE"/>
  45.                 <xs:element ref="REMARKS"/>
  46.             </xs:sequence>
  47.         </xs:complexType>
  48.     </xs:element>
  49.     <xs:element name="RETURN-YEAR">
  50.         <xs:simpleType>
  51.             <xs:restriction base="xs:string">
  52.                 <xs:length value="4"/>
  53.                 <xs:pattern value="((19|20)\d\d)"/>
  54.             </xs:restriction>
  55.         </xs:simpleType>
  56.     </xs:element>
  57.     <xs:element name="RETURN">
  58.         <xs:complexType>
  59.             <xs:sequence>
  60.                 <xs:element ref="HEADER-DATA"/>
  61.                 <xs:element ref="INVOICE-HEADER" minOccurs="0"/>
  62.                 <xs:element ref="DOCUMENT-HEADER" minOccurs="0"/>
  63.                 <xs:element ref="SELF-ASSESSMENT-MEMORANDAM"/>
  64.             </xs:sequence>
  65.             <xs:attribute ref="ToolVer" use="required"/>
  66.             <xs:attribute ref="ReturnType" use="required"/>
  67.         </xs:complexType>
  68.     </xs:element>
  69.     <xs:element name="REMARKS">
  70.         <xs:simpleType>
  71.             <xs:restriction base="xs:string">
  72.                 <xs:maxLength value="1000"/>
  73.                 <xs:minLength value="1"/>
  74.             </xs:restriction>
  75.         </xs:simpleType>
  76.     </xs:element>
  77.     <xs:element name="REGISTRATION-NUMBER">
  78.         <xs:simpleType>
  79.             <xs:restriction base="xs:string">
  80.                 <xs:pattern value="[A-Z]{5}[0-9]{4}[A-Z](XM|XD|EM|ED)[0-9]{3}"/>
  81.             </xs:restriction>
  82.         </xs:simpleType>
  83.     </xs:element>
  84.     <xs:element name="QUARTER">
  85.         <xs:simpleType>
  86.             <xs:restriction base="xs:string">
  87.                 <xs:enumeration value="Jan-Mar"/>
  88.                 <xs:enumeration value="Apr-Jun"/>
  89.                 <xs:enumeration value="Jul-Sep"/>
  90.                 <xs:enumeration value="Oct-Dec"/>
  91.                 <xs:enumeration value="jan-mar"/>
  92.                 <xs:enumeration value="apr-jun"/>
  93.                 <xs:enumeration value="jul-sep"/>
  94.                 <xs:enumeration value="oct-dec"/>
  95.                 <xs:enumeration value="JAN-MAR"/>
  96.                 <xs:enumeration value="APR-JUN"/>
  97.                 <xs:enumeration value="JUL-SEP"/>
  98.                 <xs:enumeration value="OCT-DEC"/>
  99.             </xs:restriction>
  100.         </xs:simpleType>
  101.     </xs:element>
  102.     <xs:element name="NIL-RETURN">
  103.         <xs:simpleType>
  104.             <xs:restriction base="xs:string">
  105.                 <xs:enumeration value="Yes"/>
  106.                 <xs:enumeration value="No"/>
  107.             </xs:restriction>
  108.         </xs:simpleType>
  109.     </xs:element>
  110.     <xs:element name="QUANTITY-CODE">
  111.         <xs:simpleType>
  112.             <xs:restriction base="xs:string">
  113.                 <xs:enumeration value="1KKWH"/>
  114.                 <xs:enumeration value="C/K"/>
  115.                 <xs:enumeration value="CM"/>
  116.                 <xs:enumeration value="CM3"/>
  117.                 <xs:enumeration value="G"/>
  118.                 <xs:enumeration value="GI F/S"/>
  119.                 <xs:enumeration value="KG"/>
  120.                 <xs:enumeration value="KL"/>
  121.                 <xs:enumeration value="L"/>
  122.                 <xs:enumeration value="M"/>
  123.                 <xs:enumeration value="M2"/>
  124.                 <xs:enumeration value="M3"/>
  125.                 <xs:enumeration value="MM"/>
  126.                 <xs:enumeration value="MT"/>
  127.                 <xs:enumeration value="PA"/>
  128.                 <xs:enumeration value="Q"/>
  129.                 <xs:enumeration value="T"/>
  130.                 <xs:enumeration value="TU"/>
  131.                 <xs:enumeration value="U"/>
  132.             </xs:restriction>
  133.         </xs:simpleType>
  134.     </xs:element>
  135.     <xs:element name="QUANTITY">
  136.         <xs:complexType>
  137.             <xs:simpleContent>
  138.                 <xs:extension base="ST_QUANTITY"/>
  139.             </xs:simpleContent>
  140.         </xs:complexType>
  141.     </xs:element>
  142.     <xs:element name="PLACE">
  143.         <xs:simpleType>
  144.             <xs:restriction base="xs:string">
  145.                 <xs:maxLength value="50"/>
  146.                 <xs:minLength value="1"/>
  147.             </xs:restriction>
  148.         </xs:simpleType>
  149.     </xs:element>
  150.     <xs:element name="NAME">
  151.         <xs:simpleType>
  152.             <xs:restriction base="xs:string">
  153.                 <xs:maxLength value="100"/>
  154.             </xs:restriction>
  155.         </xs:simpleType>
  156.     </xs:element>
  157.     <xs:element name="ISSUED-BY">
  158.         <xs:simpleType>
  159.             <xs:restriction base="xs:string">
  160.                 <xs:enumeration value="Importer"/>
  161.                 <xs:enumeration value="Manufacturer"/>
  162.                 <xs:enumeration value="Dealer"/>
  163.                 <xs:enumeration value="importer"/>
  164.                 <xs:enumeration value="manufacturer"/>
  165.                 <xs:enumeration value="dealer"/>
  166.                 <xs:enumeration value="IMPORTER"/>
  167.                 <xs:enumeration value="MANUFACTURER"/>
  168.                 <xs:enumeration value="DEALER"/>
  169.                 <xs:enumeration value="      Dealer"/>
  170.                 <xs:enumeration value="     Importer"/>
  171.                 <xs:enumeration value="   Manufacturer"/>
  172.             </xs:restriction>
  173.         </xs:simpleType>
  174.     </xs:element>
  175.     <xs:element name="INVOICE-PARTICULARS">
  176.         <xs:complexType>
  177.             <xs:sequence>
  178.                 <xs:element ref="INVOICE-NUMBER"/>
  179.                 <xs:element ref="INVOICE-DATE"/>
  180.                 <xs:element ref="INVOICE-ITEMS" maxOccurs="unbounded"/>
  181.             </xs:sequence>
  182.             <xs:attribute ref="SL-NO" use="required"/>
  183.         </xs:complexType>
  184.     </xs:element>
  185.     <xs:element name="INVOICE-NUMBER">
  186.         <xs:simpleType>
  187.             <xs:restriction base="xs:string">
  188.                 <xs:maxLength value="20"/>
  189.                 <xs:minLength value="1"/>
  190.             </xs:restriction>
  191.         </xs:simpleType>
  192.     </xs:element>
  193.     <xs:element name="INVOICE-ITEMS">
  194.         <xs:complexType>
  195.             <xs:sequence>
  196.                 <xs:element ref="DESCRIPTION-OF-GOODS"/>
  197.                 <xs:element ref="CETSH-NUMBER"/>
  198.                 <xs:element ref="QUANTITY-CODE"/>
  199.                 <xs:element ref="QUANTITY"/>
  200.                 <xs:element name="AMOUNT-OF-DUTY-INVOLVED">
  201.                     <xs:complexType>
  202.                         <xs:simpleContent>
  203.                             <xs:extension base="ST_AMOUNT-OF-DUTY-INVOLVED"/>
  204.                         </xs:simpleContent>
  205.                     </xs:complexType>
  206.                 </xs:element>
  207.             </xs:sequence>
  208.         </xs:complexType>
  209.     </xs:element>
  210.     <xs:element name="INVOICE-HEADER">
  211.         <xs:complexType>
  212.             <xs:sequence>
  213.                 <xs:element ref="INVOICE-PARTICULARS" maxOccurs="unbounded"/>
  214.             </xs:sequence>
  215.         </xs:complexType>
  216.     </xs:element>
  217.     <xs:element name="INVOICE-DATE">
  218.         <xs:simpleType>
  219.             <xs:restriction base="xs:string">
  220.                 <xs:pattern value="(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]([0-9]{4})"/>
  221.             </xs:restriction>
  222.         </xs:simpleType>
  223.     </xs:element>
  224.     <xs:element name="INVOICE-BILL-ENTRY-NO">
  225.         <xs:simpleType>
  226.             <xs:restriction base="xs:string">
  227.                 <xs:maxLength value="20"/>
  228.                 <xs:minLength value="1"/>
  229.             </xs:restriction>
  230.         </xs:simpleType>
  231.     </xs:element>
  232.     <xs:element name="HEADER-DATA">
  233.         <xs:complexType>
  234.             <xs:sequence>
  235.                 <xs:element ref="RETURN-YEAR"/>
  236.                 <xs:element ref="QUARTER"/>
  237.                 <xs:element ref="DEALER-NAME"/>
  238.                 <xs:element ref="REGISTRATION-NUMBER"/>
  239.                 <xs:element ref="NIL-RETURN" minOccurs="0"/>
  240.             </xs:sequence>
  241.         </xs:complexType>
  242.     </xs:element>
  243.     <xs:element name="DOCUMENT-HEADER">
  244.         <xs:complexType>
  245.             <xs:sequence>
  246.                 <xs:element ref="DOCUMENT-DETAIL" maxOccurs="unbounded"/>
  247.             </xs:sequence>
  248.         </xs:complexType>
  249.     </xs:element>
  250.     <xs:element name="DOCUMENT-DETAIL">
  251.         <xs:complexType>
  252.             <xs:sequence>
  253.                 <xs:element ref="INVOICE-BILL-ENTRY-NO"/>
  254.                 <xs:element ref="DATE"/>
  255.                 <xs:element ref="ISSUED-BY"/>
  256.                 <xs:element ref="REGISTRATION-NUMBER"/>
  257.                 <xs:element ref="NAME"/>
  258.                 <xs:element ref="ADDRESS"/>
  259.                 <xs:element ref="INVOICE-ITEMS" maxOccurs="unbounded"/>
  260.             </xs:sequence>
  261.             <xs:attribute ref="SL-NO" use="required"/>
  262.         </xs:complexType>
  263.     </xs:element>
  264.     <xs:element name="DESCRIPTION-OF-GOODS">
  265.         <xs:simpleType>
  266.             <xs:restriction base="xs:string">
  267.                 <xs:maxLength value="255"/>
  268.                 <xs:minLength value="1"/>
  269.             </xs:restriction>
  270.         </xs:simpleType>
  271.     </xs:element>
  272.     <xs:element name="DEALER-NAME">
  273.         <xs:simpleType>
  274.             <xs:restriction base="xs:string">
  275.                 <xs:maxLength value="255"/>
  276.                 <xs:minLength value="1"/>
  277.             </xs:restriction>
  278.         </xs:simpleType>
  279.     </xs:element>
  280.     <xs:element name="DATE">
  281.         <xs:simpleType>
  282.             <xs:restriction base="xs:string">
  283.                 <xs:pattern value="((0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]([0-9]{4}))"/>
  284.             </xs:restriction>
  285.         </xs:simpleType>
  286.     </xs:element>
  287.     <xs:element name="CETSH-NUMBER">
  288.         <xs:simpleType>
  289.             <xs:restriction base="xs:string">
  290.                 <xs:pattern value="([0-9]{8})"/>
  291.             </xs:restriction>
  292.         </xs:simpleType>
  293.     </xs:element>
  294.     <xs:element name="ADDRESS">
  295.         <xs:simpleType>
  296.             <xs:restriction base="xs:string">
  297.                 <xs:maxLength value="200"/>
  298.             </xs:restriction>
  299.         </xs:simpleType>
  300.     </xs:element>
  301.     <xs:element name="ACES">
  302.         <xs:complexType>
  303.             <xs:sequence>
  304.                 <xs:element ref="RETURN"/>
  305.             </xs:sequence>
  306.         </xs:complexType>
  307.     </xs:element>
  308. </xs:schema>
---------------------
Xml file(Sample.xml)


Expand|Select|Wrap|Line Numbers
  1. <ACES><RETURN ReturnType="DLR" ToolVer="1.0"><HEADER-DATA><RETURN-YEAR>2010</RETURN-YEAR><QUARTER>Jul-Sep</QUARTER><DEALER-NAME>B.H.Enterprise</DEALER-NAME><REGISTRATION-NUMBER>ABCDE1234EXD123</REGISTRATION-NUMBER><NIL-RETURN>No</NIL-RETURN></HEADER-DATA><INVOICE-HEADER><INVOICE-PARTICULARS SL-NO="1"><INVOICE-NUMBER>001</INVOICE-NUMBER><INVOICE-DATE>01/07/2010</INVOICE-DATE><INVOICE-ITEMS><DESCRIPTION-OF-GOODS>T.G.UREA</DESCRIPTION-OF-GOODS><CETSH-NUMBER>01019010</CETSH-NUMBER><QUANTITY-CODE>KG</QUANTITY-CODE><QUANTITY>2350.00</QUANTITY><AMOUNT-OF-DUTY-INVOLVED>23500.00</AMOUNT-OF-DUTY-INVOLVED></INVOICE-ITEMS></INVOICE-PARTICULARS><INVOICE-PARTICULARS SL-NO="2"><INVOICE-NUMBER>002</INVOICE-NUMBER><INVOICE-DATE>02/07/2010</INVOICE-DATE><INVOICE-ITEMS><DESCRIPTION-OF-GOODS>T.G.UREA</DESCRIPTION-OF-GOODS><CETSH-NUMBER>01011090</CETSH-NUMBER><QUANTITY-CODE>KG</QUANTITY-CODE><QUANTITY>8210.00</QUANTITY><AMOUNT-OF-DUTY-INVOLVED>82100.00</AMOUNT-OF-DUTY-INVOLVED></INVOICE-ITEMS></INVOICE-PARTICULARS></INVOICE-HEADER><DOCUMENT-HEADER><DOCUMENT-DETAIL SL-NO="1"><INVOICE-BILL-ENTRY-NO>05259</INVOICE-BILL-ENTRY-NO><DATE>30/06/2010</DATE><ISSUED-BY>Dealer</ISSUED-BY><REGISTRATION-NUMBER>ABCDE1235EXD123</REGISTRATION-NUMBER><NAME>RCF</NAME><ADDRESS>zzzzzzzzzzzzzz</ADDRESS><INVOICE-ITEMS><DESCRIPTION-OF-GOODS>TG UREA</DESCRIPTION-OF-GOODS><CETSH-NUMBER>01019010</CETSH-NUMBER><QUANTITY-CODE>KG</QUANTITY-CODE><QUANTITY>1000.00</QUANTITY><AMOUNT-OF-DUTY-INVOLVED>100000.00</AMOUNT-OF-DUTY-INVOLVED></INVOICE-ITEMS></DOCUMENT-DETAIL><DOCUMENT-DETAIL SL-NO="2"><INVOICE-BILL-ENTRY-NO>059626</INVOICE-BILL-ENTRY-NO><DATE>30/06/2010</DATE><ISSUED-BY>Dealer</ISSUED-BY><REGISTRATION-NUMBER>ABCDE1236EXD123</REGISTRATION-NUMBER><NAME>LIVE PHARMA</NAME><ADDRESS>ABCDE1235EXD123</ADDRESS><INVOICE-ITEMS><DESCRIPTION-OF-GOODS>T.G.UREA</DESCRIPTION-OF-GOODS><CETSH-NUMBER>01019010</CETSH-NUMBER><QUANTITY-CODE>KG</QUANTITY-CODE><QUANTITY>5000.00</QUANTITY><AMOUNT-OF-DUTY-INVOLVED>500000.00</AMOUNT-OF-DUTY-INVOLVED></INVOICE-ITEMS></DOCUMENT-DETAIL></DOCUMENT-HEADER><SELF-ASSESSMENT-MEMORANDAM><DATE>30/09/2010</DATE><PLACE>MUMBAI</PLACE><REMARKS>xxxxxxxxxxxxxxxxxxxx</REMARKS></SELF-ASSESSMENT-MEMORANDAM></RETURN></ACES>
'---------------------
vb code in form load event

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Validate "C:\XmlTest\Sample.xml", "C:\XmlTest\Aces_Dlr.xsd"
  3. End Sub
  4.  
  5.  Private Function Validate(ByVal strXMLPath As String, _
  6.                               ByVal strXSDPath As String) As Boolean
  7.  
  8.         Dim objSchemas As MSXML2.XMLSchemaCache40
  9.         Dim objXML As MSXML2.DOMDocument40
  10.         Dim objXSD As MSXML2.DOMDocument40
  11.         Dim strNamespace As String
  12.  
  13.         Dim objErr As MSXML2.IXMLDOMParseError
  14.         ' load XSD as DOM to populate in Schema Cache
  15.         Set objXSD = New MSXML2.DOMDocument40
  16.         objXSD.async = False
  17.         If Not objXSD.Load(strXSDPath) Then
  18.             Err.Raise 1, "Validate", "Load XSD failed: " & objXSD.parseError.reason
  19.         Else
  20.  
  21.             ' get namespace name from XSD targetNamespace attribute
  22.             'strNamespace = "urn:sample"
  23.             strNamespace = objXSD.documentElement.getAttribute("targetNamespace")
  24.         End If
  25.  
  26.         ' populate schema cache
  27.         Set objSchemas = New MSXML2.XMLSchemaCache40
  28.         objSchemas.Add strNamespace, objXSD
  29.  
  30.         ' load XML file (without validation - that comes later)
  31.         Set objXML = New MSXML2.DOMDocument40
  32.         objXML.async = False
  33.         objXML.validateOnParse = False
  34.         objXML.resolveExternals = False
  35.  
  36.         ' load XML, without any validation
  37.         If Not objXML.Load(strXMLPath) Then
  38.             Err.Raise 1, "Validate", "Load XML failed: " & objXML.parseError.reason
  39.         End If
  40.  
  41.         ' bind Schema Cache to DOM
  42.         Set objXML.schemas = objSchemas
  43.  
  44.         ' does this XML measure up?
  45.         Set objErr = objXML.Validate()
  46.  
  47.         ' any good?
  48.         Validate = (objErr.errorCode = 0)
  49.         If objErr.errorCode <> 0 Then
  50.             MsgBox objErr.reason
  51.             'Err.Raise 1, "Validate", objErr.reason
  52.             Exit Function
  53.         End If
  54.  
  55.     End Function


Please help me, it's urgent

thanx
Oct 26 '10 #1
3 8492
Dormilich
8,652 Expert Mod 8TB
which error do you get?
Oct 26 '10 #2
Run time error – ‘-2147467259(80004005)’:
File : ///c:/XmlTest/Aces_Dlr.xsd#/schema[1]/element[position()=9 and @name = ‘QUANTITY]/complexType[1]/simpleContent[1]/extension[1]
Undeclared XSD type : ‘ST_Quantity’.
Oct 28 '10 #3
jkmyoung
2,057 Expert 2GB
It really has to do with the
xmlns:n="urn:sample"
targetNamespace="urn:sample"

Is this the namespace you want to validate for? If so, everytime you refer to a type within the schema, you must put the prefix before it, eg:
<xs:attribute ref="n:ToolVer" use="required"/> OR
<xs:extension base="n:ST_QUANTITY"/>

I would decide what you really want before making 20-30 minor changes to your schema.
Oct 28 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Christian | last post: by
reply views Thread by First_step_to_xml | last post: by
1 post views Thread by S | last post: by
1 post views Thread by Pathik | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.