Hi Aleksandar,

The SAX parser springs immediately to my mind too.

Isolate your document fragment in a string variable.  Wrap the fragment 
into a valid root key and parse that.  You could then override the parse 
method of DefaultHandler as follows:

public class FragParser extends DefaultHandler {

  private ParserAdapter parser;

  public FragParser () throws SAXException {
      System.setProperty("org.xml.sax.parser", 
"org.apache.xerces.parsers.SAXParser");
      parser = new ParserAdapter ();
      parser.setContentHandler(this);
  }

  public void parse (String rawFrag) {
   throws java.io.IOException, SAXException {
      String docFrag = "<?xml version="1.0" encoding="UTF-8" 
standalone="yes"?>\n<RootElement>"
         + rawFrag
         + "\n</RootElement>";
      InputStream instream = new StringBufferInputStream (docFrag);
      parser.parse (new InputSource (zipin));
  }

}

You would have to override the event handler as well to do anything special 
with the content of your document fragment.  You could also expand the 
wrapping around the document fragment to get more control over the document 
and add name-spaces, etc.

Hope this helps.

Cheers,
Paul.

-----Original Message-----
From:   Aleksandar Milanovic [SMTP:[EMAIL PROTECTED]
Sent:   Wednesday, September 03, 2003 9:49 AM
To:     Xerces-J-User
Subject:        validating document fragments/elements

Hi All,

Is there a way to validate only parts of documents, e.g. document fragments
whose roots are global elements? This would be very useful in the case when
a small update is done on a very large document (e.g. tens of megs in 
size).

I thought about using SAX-based validation, but even for that you need to
start with a document. Perhaps the solution is to fake the SAX events for
XML document and its parent-child relationship to the document element,
which is actually the root of everything you want to validate.

For example, suppose we need to validate a document fragment whose root
element is <validationroot>. We could fake SAX events for the document
header and perhaps for the validationroot's namespace bindings too before 
we
start generating real SAX events from the contents of <validationroot>.

Any ideas?

Alex


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to