/** * Perform a pre-order traversal non-recursive style. * * Note that TreeWalker assumes that the subtree is intended to represent * a complete (though not necessarily well-formed) document and, during a * traversal, startDocument and endDocument will always be issued to the * SAX listener. * * @param pos Node in the tree where to start traversal * * @throws TransformerException */ public void traverse(Node pos) throws org.xml.sax.SAXException { this.m_contentHandler.startDocument(); traverseFragment(pos); this.m_contentHandler.endDocument(); }
@Override public final void startElement( final String namespaceURI, final String localName, final String qName, final Attributes list) throws SAXException { if (subdocument) { subdocumentHandler.startElement(namespaceURI, localName, qName, list); } else if (localName.equals(subdocumentRoot)) { subdocumentHandler = subdocumentHandlerFactory.createContentHandler(); subdocumentHandler.startDocument(); subdocumentHandler.startElement(namespaceURI, localName, qName, list); subdocument = true; } else if (rootHandler != null) { rootHandler.startElement(namespaceURI, localName, qName, list); } }
@Test public void partial() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT)); eventReader.nextTag(); // skip to root StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader); ContentHandler contentHandler = mock(ContentHandler.class); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource()); verify(contentHandler).startDocument(); verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class)); verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child"); verify(contentHandler).endDocument(); }
@Test public void partial() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT)); streamReader.nextTag(); // skip to root assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"), streamReader.getName()); streamReader.nextTag(); // skip to child assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"), streamReader.getName()); StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader); ContentHandler contentHandler = mock(ContentHandler.class); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource()); verify(contentHandler).setDocumentLocator(any(Locator.class)); verify(contentHandler).startDocument(); verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class)); verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child"); verify(contentHandler).endDocument(); }
/** * Perform a pre-order traversal non-recursive style. * * Note that TreeWalker assumes that the subtree is intended to represent * a complete (though not necessarily well-formed) document and, during a * traversal, startDocument and endDocument will always be issued to the * SAX listener. * * @param pos Node in the tree where to start traversal * * @throws TransformerException */ public void traverse(Node pos) throws org.xml.sax.SAXException { this.m_contentHandler.startDocument(); traverseFragment(pos); this.m_contentHandler.endDocument(); }
@Override public final void startElement( final String namespaceURI, final String localName, final String qName, final Attributes list) throws SAXException { if (subdocument) { subdocumentHandler.startElement(namespaceURI, localName, qName, list); } else if (localName.equals(subdocumentRoot)) { String name = list.getValue("name"); if (name == null || name.length() == 0) { throw new SAXException("Class element without name attribute."); } try { entryElement.openEntry(isXml ? name + ".class.xml" : name + ".class"); } catch (IOException ex) { throw new SAXException(ex.toString(), ex); } subdocumentHandler = subdocumentHandlerFactory.createContentHandler(); subdocumentHandler.startDocument(); subdocumentHandler.startElement(namespaceURI, localName, qName, list); subdocument = true; } }
/** * Called by the transformer to parse the "input source". We ignore the input source and, instead, * generate SAX events to the {@link #setContentHandler ContentHandler}. */ @Override public void parse(InputSource input) throws SAXException { Assert.assertTrue(this.handler != null); handler.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", ID, "", String.valueOf(this.system.getConfig().getSystemId())); handler.startElement("", DISTRIBUTED_SYSTEM, DISTRIBUTED_SYSTEM, atts); // Add generation methods here try { generateRemoteCommand(); generateDiscovery(); generateSSL(); generateCacheServers(); } catch (AdminException ex) { throw new SAXException( "An AdminException was thrown while generating XML.", ex); } handler.endElement("", DISTRIBUTED_SYSTEM, DISTRIBUTED_SYSTEM); handler.endDocument(); }
/** * {@inheritDoc} */ public void parse(XMLWritable xml) throws IOException, SAXException { if (xml == null) throw new NullPointerException("Parameter projectTeam must not be null"); if (this.handler == null) throw new IllegalStateException("ContentHandler not set"); // start handling the document this.handler.startDocument(); XMLWriter xw = new XMLWriterSAX(this.handler); xml.toXML(xw); this.handler.endDocument(); }
this.m_contentHandler.startDocument(); break; case DTM.ELEMENT_NODE : this.m_contentHandler.startElement(ns, m_dtm.getLocalName(node), m_dtm.getNodeName(node),
@Test public void marshalSaxResult() throws Exception { ContentHandler contentHandler = mock(ContentHandler.class); SAXResult result = new SAXResult(contentHandler); marshaller.marshal(flight, result); InOrder ordered = inOrder(contentHandler); ordered.verify(contentHandler).startDocument(); ordered.verify(contentHandler).startElement(eq(""), eq("flight"), eq("flight"), isA(Attributes.class)); ordered.verify(contentHandler).startElement(eq(""), eq("flightNumber"), eq("flightNumber"), isA(Attributes.class)); ordered.verify(contentHandler).characters(isA(char[].class), eq(0), eq(2)); ordered.verify(contentHandler).endElement("", "flightNumber", "flightNumber"); ordered.verify(contentHandler).endElement("", "flight", "flight"); ordered.verify(contentHandler).endDocument(); }
public void parse() throws IOException, SAXException { if (_dom != null) { boolean isIncomplete = (_dom.getNodeType() != org.w3c.dom.Node.DOCUMENT_NODE); if (isIncomplete) { _sax.startDocument(); parse(_dom); _sax.endDocument(); } else { parse(_dom); } } }
this.m_contentHandler.startDocument(); break; case DTM.ELEMENT_NODE : this.m_contentHandler.startElement(ns, m_dtm.getLocalName(node), m_dtm.getNodeName(node),
@Test public void marshalSAXResult() throws Exception { ContentHandler contentHandler = mock(ContentHandler.class); SAXResult result = new SAXResult(contentHandler); marshaller.marshal(flights, result); InOrder ordered = inOrder(contentHandler); ordered.verify(contentHandler).setDocumentLocator(isA(Locator.class)); ordered.verify(contentHandler).startDocument(); ordered.verify(contentHandler).startPrefixMapping("", "http://samples.springframework.org/flight"); ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("flights"), isA(Attributes.class)); ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("flight"), isA(Attributes.class)); ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("number"), isA(Attributes.class)); ordered.verify(contentHandler).characters(isA(char[].class), eq(0), eq(2)); ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "number", "number"); ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flight", "flight"); ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flights", "flights"); ordered.verify(contentHandler).endPrefixMapping(""); ordered.verify(contentHandler).endDocument(); }
this.m_contentHandler.startDocument(); this.m_contentHandler.endDocument();
/** * Create a processor that writes to the file named and may or may not * also output to the screen, as specified. * * @param out output stream to write * @throws IOException on any error */ public XmlEditsVisitor(OutputStream out) throws IOException { this.out = out; factory =(SAXTransformerFactory)SAXTransformerFactory.newInstance(); try { TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8"); handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); handler.getTransformer().setOutputProperty(XML_INDENTATION_PROP, XML_INDENTATION_NUM); handler.getTransformer().setOutputProperty(OutputKeys.STANDALONE, "yes"); handler.setResult(new StreamResult(out)); contentHandler = handler; contentHandler.startDocument(); contentHandler.startElement("", "", "EDITS", new AttributesImpl()); } catch (TransformerConfigurationException e) { throw new IOException("SAXTransformer error: " + e.getMessage()); } catch (SAXException e) { throw new IOException("SAX error: " + e.getMessage()); } }
_sax.setDocumentLocator(this); _sax.startDocument(); Node next = node.getFirstChild(); while (next != null) { next = next.getNextSibling(); _sax.endDocument(); break; _sax.startElement(uri, localName, qname, attrs);
this.m_contentHandler.startDocument(); this.m_contentHandler.endDocument();
@Override protected void handleStartDocument() throws SAXException { handler.startDocument(); handler.startElement(NSURI_JSP, "root", PREFIX_JSP + ":root", EMPTY_ATTRS); }
inDocHandler.startDocument(); inDocHandler.startElement("", "classes", "classes", new AttributesImpl()); inDocHandler.endDocument();
/** * Parses a subtree starting from the element e and * reports SAX2 events to the specified handler. * * @deprecated in JAXB 2.0 * Use {@link #scan(Element)} */ public void parse( Element e, ContentHandler handler ) throws SAXException { // it might be better to set receiver at the constructor. receiver = handler; setCurrentLocation( e ); receiver.startDocument(); receiver.setDocumentLocator(locator); visit(e); setCurrentLocation( e ); receiver.endDocument(); }