SOS:JAXP1.3 how to capture parent tag details in DOM-schemaValidation

Discussion in 'Java' started by chetan.33@gmail.com, Apr 3, 2006.

  1. Guest

    OBJECTIVE---
    I need to carry out validation for my XML file against a schema. My XML
    contains Multiple record data each having multiple columns in it.
    I want to carry out following
    1 - validate XML against schema
    2- delete the invalid Records from the DOM schema of the XML file
    validated
    3- get error message generated by Validator for failures
    4- get column tag names and data where attributes defines them as
    unique for reporting
    5 - use the DOM object to do other business operations

    #####################
    PROBLEM
    6--- I am able to carry out 1, 3, and 5 as well
    7--- am unable to get solution for 4 - NEED HELP FOR THIS
    8--- want to know whether for step 2 there is a better way to delete
    the invalid records during validation itself for any validation failure
    in its child tag? - NEED HELP FOR THIS

    #####################
    CODE approach followed SO FAR I S based on
    http://java.sun.com/developer/technicalArticles/xml/jaxp1-3/
    which allows DOM to be validated against schema
    ---
    FOR sample xml file
    <data>
    <record rownum='1'>
    <columnA isUNique="Y">data1</columnA>
    <columnB>data2</columnB>
    </record>
    <record rownum='2'>
    <columnA isUNique="Y">data3</columnA>
    <columnB>data4</columnB>
    </record>
    <record rownum='3'>
    ......
    </record>
    </data>

    //SchemaFactory used to compile schema and get a Schema object:
    // Load Schema
    String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
    SchemaFactory factory = SchemaFactory.newInstance(language);
    factory.setErrorHandler(new MySchemaErrorHandler());
    //factory.setResourceResolver( new MyLSResourceResolver());
    StreamSource ss = new StreamSource(new File("mySchema.xsd")));
    Schema schema = factory.newSchema(ss);

    // Load XML
    File xmlFile = new File("data.xml");
    DocumentBuilder parser =
    DocumentBuilderFactory.newInstance().newDocumentBuilder();
    document = parser.parse(xmlFile);

    // Validate

    .......
    Validator validator = schema.newValidator();
    validator.setErrorHandler( new ErrorHandlerImpl());
    DOMResult result = new DOMResult();
    validator.validate(new DOMSource(document), result);


    /*
    //validator.validate(new StreamSource(<XML Document>));
    used alternative for validator to validate the instance document or DOM
    object in memory, with the augmented result sent to DOMResult.
    */
    #####################
    Thanks to all in advance
     
    , Apr 3, 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. =?Utf-8?B?Sm9l?=

    Show Details/Hide Details link button

    =?Utf-8?B?Sm9l?=, Mar 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    950
    dkode
    Mar 13, 2006
  2. Max
    Replies:
    7
    Views:
    9,184
  3. shruds
    Replies:
    1
    Views:
    938
    John C. Bollinger
    Jan 27, 2006
  4. randy.buchholz

    Capture PK violation in Details View

    randy.buchholz, Apr 29, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    292
    randy.buchholz
    Apr 29, 2008
  5. Mark D. Anderson
    Replies:
    4
    Views:
    112
    Mark D. Anderson
    Jul 27, 2003
Loading...

Share This Page