[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Serialization with SAX

  • From: Johannes Lichtenberger <Johannes.Lichtenberger@u...>
  • To: Michael Kay <mike@s...>
  • Date: Fri, 16 Jan 2009 00:41:40 +0100

RE:  Serialization with SAX
Am Donnerstag, den 15.01.2009, 22:03 +0000 schrieb Michael Kay:
> You don't want to get the source of a serializer and modify it. You want to
> add a SAX filter into a pipeline. Your filter should simply call the next
> stage in the pipeline (that is, the serializer) for every event until the
> threshold is reached, and do nothing for events after that threshold (except
> of course for closing the outermost element and the document tidily).
> 
> You can write a SAX filter by subclassing XMLFilterImpl, and you can see how
> to use it from a tutorial at
> http://www.cafeconleche.org/slides/sd2000east/sax/74.html 

So I'm not really sure how to use it, something like:

  public ExtractArticles(XMLReader parent) {
    super(parent);
  }
  
  public void parse(InputSource input) throws IOException, SAXException
{
    super.parse(input);
  }
  
  public void parse(String systemId) throws IOException, SAXException {
    parse(new InputSource(systemId)); 
  }

    /**
   * {@inheritDoc}
   */
  public void startElement(String namespaceURI, String localName, String
qName,
      Attributes atts) throws SAXException {

    if (localName.equalsIgnoreCase("page")) {
      counter++;
    }

    if (counter < ARTICLES) {
      super.startElement(namespaceURI, localName, qName, atts);
    }
  }

  ...

  public final static void main(final String args[]) {

    try {
      XMLReader r = XMLReaderFactory.createXMLReader();
      
      new ExtractArticles(r).parse(new InputSource(new
FileInputStream(args[0])));
    } catch (IOException e) {
      System.err.println("I/O exception reading XML document");
    } catch (SAXException e) {
      System.err.println("XML exception reading document.");
    }

  }

But how do I specify the output document?

greetings,
Johannes



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.