public void startTagClosed(int index, String name) throws IOException { startTagOpen(index, name); closeStartTag(); }
public void closeEmptyTag() throws IOException { incrementNesting(); decrementNesting(); this.currentElement = this.currentElement.getParentElement(); }
public void startTagNamespaces(int index, String name, int[] nums, String[] prefs) throws IOException { // find the namespaces actually being declared int[] deltas = openNamespaces(nums, prefs); // create the start tag for element startTagOpen(index, name); // add namespace declarations to open element for (int i = 0; i < deltas.length; i++) { int slot = deltas[i]; this.currentElement.addNamespaceDeclaration(getNamespace(slot)); } }
/** * Marshal this message to DOM. * @param message * @return DOM tree */ public static Element marshalObjectToDOM(Object message) { try { IBindingFactory jc = BindingDirectory.getFactory(message.getClass()); IMarshallingContext marshaller = jc.createMarshallingContext(); String[] namespaces = jc.getNamespaces(); JDOMWriter jdomWriter = new JDOMWriter(namespaces); marshaller.setXmlWriter(jdomWriter); marshaller.marshalDocument(message); marshaller.endDocument(); org.jdom.Document jdoc = jdomWriter.getDocument(); DOMOutputter dout = new DOMOutputter(); Document doc = dout.output(jdoc); Element node = doc.getDocumentElement(); return node; } catch (JiBXException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } return null; } /**
/** * This will retrieve (if in existence) or create (if not) a * <code>Namespace</code> for the supplied namespace index. */ private Namespace getNamespace(int index) { String prefix = getNamespacePrefix(index); String uri = getNamespaceUri(index); if(prefix == null) { return Namespace.getNamespace(uri); } else { return Namespace.getNamespace(prefix, uri); } } }
public void startTagOpen(int index, String name) throws IOException { Element newElement = new Element(name, getNamespace(index)); if(this.currentElement == null) { this.document.setRootElement(newElement); } else { this.currentElement.addContent(newElement); } this.currentElement = newElement; }
/** * Creates a new instance with the given namespace URIs. * @param namespaces namespaces */ public JDOMWriter(String[] namespaces) { super(namespaces); reset(); }
public void closeStartTag() throws IOException { incrementNesting(); }
public void endTag(int index, String name) throws IOException { decrementNesting(); this.currentElement = this.currentElement.getParentElement(); }
/** * Marshal this message to DOM. * @param message * @return DOM tree */ public static Element marshalObjectToDOM(Object message) { try { IBindingFactory jc = BindingDirectory.getFactory(message.getClass()); IMarshallingContext marshaller = jc.createMarshallingContext(); String[] namespaces = jc.getNamespaces(); JDOMWriter jdomWriter = new JDOMWriter(namespaces); marshaller.setXmlWriter(jdomWriter); marshaller.marshalDocument(message); marshaller.endDocument(); org.jdom.Document jdoc = jdomWriter.getDocument(); DOMOutputter dout = new DOMOutputter(); Document doc = dout.output(jdoc); Element node = doc.getDocumentElement(); return node; } catch (JiBXException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } return null; } /**
public void addAttribute(int index, String name, String value) throws IOException { this.currentElement.setAttribute(name, value, getNamespace(index)); }