tags:

views:

50

answers:

2

Is a SAX Parser capable of capturing mixed content within an XML document (see example below)?

<element>here is some <b>mixed content</b></element>

+3  A: 

Of course. You get the following events:

  1. startElement (element)
  2. characters ("here is some ")
  3. startElement (b)
  4. characters ("mixed content")
  5. endElement (b)
  6. endElement (element)
Chris Jester-Young
+1  A: 

Yes, although I'm not sure what you mean by capturing. If you run the short example below, you'll see the startElement handler called for both element and b:

String xml = "<element>here is some <b>mixed content</b></element>";
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new ByteArrayInputStream(xml.getBytes()), new DefaultHandler(){
    @Override
    public void startElement(String uri, String localName, String name,
            Attributes attributes) throws SAXException {
        System.out.println("Started: "+name);
    }
});
Kevin