Validation a DOM-Tree (Document-Instance) with a XML-Schema

Discussion in 'Java' started by Fabio, Sep 8, 2004.

  1. Fabio

    Fabio Guest

    Hi,

    I like to validate a XML-Document-Instance (below =doc).


    /**********************java-Code*************************
    *********************************************************
    */
    DocumentBuilderFactory dbf=null;
    Document doc=null;
    dbf = DocumentBuilderFactory.newInstance();
    DOMParser dp=new DOMParser();

    DocumentBuilder db=null;
    try {
    db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e2) {
    // TODO Automatisch erstellter Catch-Block
    e2.printStackTrace();
    }
    doc=db.newDocument();
    Element e=doc.createElementNS("xsi","root" );
    Attr at=doc.createAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi");
    at.setNodeValue("http://www.w3.org/2001/XMLSchema-instance");
    Attr schLoc=doc.createAttributeNS("anyXMLSchema.xsd","xsi:noNamespaceSchemaLocation");
    schLoc.setNodeValue("anyXMLSchema.xsd");
    Element e1=doc.createElement("child");
    e1.appendChild(doc.createTextNode("12"));
    e.setAttributeNodeNS(at);
    e.setAttributeNodeNS(schLoc);
    e.appendChild(e1);

    // doc-Instance
    doc.appendChild(e);
    /************************JAVA-Code end*******************
    *********************************************************
    */

    my first problem is i can't use jdk 1.5


    I found this below code from apache.org from Example DOM3.java

    /***********************JAVA-Code**************************
    *********************************************************
    */
    ..........
    // set error handler on the Document
    config = doc.getDomConfig(); // <-- can't use this method

    config.setParameter("error-handler", errorHandler);

    // set validation feature
    config.setParameter("validate", Boolean.TRUE);
    config.setParameter("schema-type",
    "http://www.w3.org/2001/XMLSchema");
    config.setParameter("schema-location","data/personal.xsd");

    // remove comments from the document
    config.setParameter("comments", Boolean.FALSE);

    System.out.println("Normalizing document... ");
    doc.normalizeDocument();
    .....

    /**********************JAVA-Code end*********************
    *********************************************************
    */
    But it not functioned

    Can somebody give me a example, for validating a Doc-Instance with
    a XML-Schema ???????????????

    thank a lot
    Fabio, Sep 8, 2004
    #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. Markus
    Replies:
    1
    Views:
    1,497
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,170
    Stanimir Stamenkov
    Apr 25, 2005
  3. Joris Gillis
    Replies:
    2
    Views:
    1,522
    Joris Gillis
    Jun 16, 2006
  4. Replies:
    3
    Views:
    2,796
  5. Replies:
    5
    Views:
    980
    Brian McCauley
    Nov 29, 2006
Loading...

Share This Page