validation problem

Discussion in 'XML' started by sk, Jul 4, 2006.

  1. sk

    sk Guest

    I am trying to make validation program but getting the following error.

    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of
    element 'tag1'.

    I attached the xml document and schema as well as the java program to
    validate the xml doc.



    //java program to validate the xml document
    DocumentBuilder parser =
    DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = parser.parse(new File("c:\\myxmldoc.xml"));

    // Create a SchemaFactory capable of understanding WXS schemas.
    SchemaFactory factory =

    SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

    // Load a WXS schema, represented by a Schema instance.
    javax.xml.transform.Source schemaFile = new
    javax.xml.transform.stream.StreamSource(new File("c:\\XMLType2.xsd"));
    Schema schema = factory.newSchema(schemaFile);

    // Create a Validator object, which can be used to validate
    Validator validator = schema.newValidator();

    // Validate the DOM tree.
    validator.validate(new javax.xml.transform.dom.DOMSource(document));

    //xml document////////
    <?xml version="1.0"?>
    <tag1 >
    hello world
    </tag1>

    //schema///////////////////
    <?xml version="1.0" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="tag1">
    <xs:simpleType>
    <xs:restriction base="xs:string" >
    <xs:maxLength value="50" />
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:schema>
     
    sk, Jul 4, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,703
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,524
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    Tommy
    Nov 29, 2003
  4. Matt
    Replies:
    14
    Views:
    4,144
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  5. bnp
    Replies:
    4
    Views:
    336
Loading...

Share This Page