private Element createExcludeElement(String exclude) { Element element = document.createElementNS(RULESET_2_0_0_NS_URI, "exclude"); element.setAttribute("name", exclude); return element; }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { Node parent = getParent(); Element element = this.document.createElementNS(uri, qName); for (int i = 0; i < attributes.getLength(); i++) { String attrUri = attributes.getURI(i); String attrQname = attributes.getQName(i); String value = attributes.getValue(i); if (!attrQname.startsWith("xmlns")) { element.setAttributeNS(attrUri, attrQname, value); } } element = (Element) parent.appendChild(element); this.elements.add(element); }
private Element createTextElement(String name, String value) { Element element = document.createElementNS(RULESET_2_0_0_NS_URI, name); Text text = document.createTextNode(value); element.appendChild(text); return element; }
/** * Use to append default types XML elements, use by the save() method. * * @param root * XML parent element use to append this default type element. * @param entry * The values to append. * @see #save(java.io.OutputStream) */ private void appendDefaultType(Element root, Entry<String, String> entry) { Element defaultType = root.getOwnerDocument().createElementNS(TYPES_NAMESPACE_URI, DEFAULT_TAG_NAME); defaultType.setAttribute(EXTENSION_ATTRIBUTE_NAME, entry.getKey()); defaultType.setAttribute(CONTENT_TYPE_ATTRIBUTE_NAME, entry.getValue()); root.appendChild(defaultType); }
@Override public Document createComponentXML() throws ParserConfigurationException { Document doc = super.createComponentXML(); NodeList nodes = doc.getElementsByTagName(getComponentTypeString()); assert nodes.getLength() == 1; Element voiceElt = (Element) nodes.item(0); voiceElt.setAttribute("type", type); voiceElt.setAttribute("gender", gender); Element dependsElt = (Element) voiceElt.appendChild(doc.createElementNS(ComponentDescription.installerNamespaceURI, "depends")); dependsElt.setAttribute("language", dependsLanguage); dependsElt.setAttribute("version", dependsVersion); return doc; } }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); Element newEl = getInstance().getMetadata().createElementNS(uri, qName); for (int i = 0; i < attributes.getLength(); i++) { newEl.setAttributeNS( attributes.getURI(i), attributes.getQName(i), attributes.getValue(i) ); } current.appendChild(newEl); current = newEl; }
@Test public void marshalDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document result = builder.newDocument(); DOMResult domResult = new DOMResult(result); marshaller.marshal(flights, domResult); Document expected = builder.newDocument(); Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights"); Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns"); namespace.setNodeValue("http://samples.springframework.org/flight"); flightsElement.setAttributeNode(namespace); expected.appendChild(flightsElement); Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight"); flightsElement.appendChild(flightElement); Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number"); flightElement.appendChild(numberElement); Text text = expected.createTextNode("42"); numberElement.appendChild(text); assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected)); }
private Element createCDATASectionElement(String name, String value) { Element element = document.createElementNS(RULESET_2_0_0_NS_URI, name); CDATASection cdataSection = document.createCDATASection(value); element.appendChild(cdataSection); return element; } }
public void startElement(String namespace, String localName, String qName, Attributes attrs) final Element tmp = (Element)_document.createElementNS(namespace, qName); tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, (String) _namespaceDecls.elementAt(i)); tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, (String) _namespaceDecls.elementAt(i)); for (int i = 0; i < nattrs; i++) { if (attrs.getLocalName(i) == null) { tmp.setAttribute(attrs.getQName(i), attrs.getValue(i)); tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i));
protected Element writeBodyElement(Document d) { Element envelopeElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Envelope"); Attr encodingStyleAttr = d.createAttributeNS(Constants.SOAP_NS_ENVELOPE, "s:encodingStyle"); encodingStyleAttr.setValue(Constants.SOAP_URI_ENCODING_STYLE); envelopeElement.setAttributeNode(encodingStyleAttr); d.appendChild(envelopeElement); Element bodyElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Body"); envelopeElement.appendChild(bodyElement); return bodyElement; }
public static Element insertChild(Document doc, Element element, String name, String namespace, int indent) { Node node = doc.createTextNode("\n"+Utilities.padLeft("", ' ', indent)); Element child = doc.createElementNS(namespace, name); element.insertBefore(child, element.getFirstChild()); element.insertBefore(node, element.getFirstChild()); return child; }
/** * Use to append specific type XML elements, use by the save() method. * * @param root * XML parent element use to append this override type element. * @param entry * The values to append. * @see #save(java.io.OutputStream) */ private void appendSpecificTypes(Element root, Entry<PackagePartName, String> entry) { Element specificType = root.getOwnerDocument().createElementNS(TYPES_NAMESPACE_URI, OVERRIDE_TAG_NAME); specificType.setAttribute(PART_NAME_ATTRIBUTE_NAME, entry.getKey().getName()); specificType.setAttribute(CONTENT_TYPE_ATTRIBUTE_NAME, entry.getValue()); root.appendChild(specificType); }
@Override public Document createComponentXML() throws ParserConfigurationException { Document doc = super.createComponentXML(); NodeList nodes = doc.getElementsByTagName(getComponentTypeString()); assert nodes.getLength() == 1; Element voiceElt = (Element) nodes.item(0); voiceElt.setAttribute("type", type); voiceElt.setAttribute("gender", gender); Element dependsElt = (Element) voiceElt.appendChild(doc.createElementNS(ComponentDescription.installerNamespaceURI, "depends")); dependsElt.setAttribute("language", dependsLanguage); dependsElt.setAttribute("version", dependsVersion); return doc; } }
public static Element appendNewElement(Document document, Element parent, String element, Object content, String namespace) { Element childElement; if (namespace != null) { childElement = document.createElementNS(namespace, element); } else { childElement = document.createElement(element); } if (content != null) { // TODO: We'll have that on Android 2.2: // childElement.setTextContent(content.toString()); // Meanwhile: childElement.appendChild(document.createTextNode(content.toString())); } parent.appendChild(childElement); return childElement; }
public void drawIcon(final int imageX, final int imageYo, final int iconPadding, final ProcessDiagramSVGGraphics2D svgGenerator) { Element gTag = svgGenerator.getDOMFactory().createElementNS(null, SVGGraphics2D.SVG_G_TAG); gTag.setAttributeNS(null, "transform", "translate(" + (imageX) + "," + (imageYo) + ")"); Element pathTag = svgGenerator.getDOMFactory().createElementNS(null, SVGGraphics2D.SVG_PATH_TAG); pathTag.setAttributeNS(null, "d", this.getDValue()); pathTag.setAttributeNS(null, "fill", this.getFillValue()); pathTag.setAttributeNS(null, "stroke", this.getStrokeValue()); gTag.appendChild(pathTag); svgGenerator.getExtendDOMGroupManager().addElement(gTag); }
@Test public void marshalEmptyDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); DOMResult domResult = new DOMResult(); marshaller.marshal(flights, domResult); assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document); Document result = (Document) domResult.getNode(); Document expected = builder.newDocument(); Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights"); Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns"); namespace.setNodeValue("http://samples.springframework.org/flight"); flightsElement.setAttributeNode(namespace); expected.appendChild(flightsElement); Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight"); flightsElement.appendChild(flightElement); Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number"); flightElement.appendChild(numberElement); Text text = expected.createTextNode("42"); numberElement.appendChild(text); assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected)); }
private Element createRootUrlElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTER_ELEMENT_NAME); Element urlElement = createUrlElement(doc, clusteringServiceConfiguration); rootElement.appendChild(urlElement); return rootElement; }
@Override protected Element createRootElement(Document doc, LookupTransactionManagerProviderConfiguration lookupTransactionManagerProviderConfiguration) { Element rootElement = doc.createElementNS(NAMESPACE.toString(), TRANSACTION_NAMESPACE_PREFIX + TRANSACTION_ELEMENT_NAME); rootElement.setAttribute(TRANSACTION_LOOKUP_CLASS, lookupTransactionManagerProviderConfiguration.getTransactionManagerLookup() .getName()); return rootElement; }
if (getDigester().getNamespaceAware()) { element = doc.createElementNS(namespaceURI, name); for (int i = 0; i < attributes.getLength(); i++) { element.setAttributeNS(attributes.getURI(i), attributes.getQName(i), attributes.getValue(i)); element = doc.createElement(name); for (int i = 0; i < attributes.getLength(); i++) { element.setAttribute(attributes.getQName(i), attributes.getValue(i));
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { Node parent = getParent(); Element element = this.document.createElementNS(uri, qName); for (int i = 0; i < attributes.getLength(); i++) { String attrUri = attributes.getURI(i); String attrQname = attributes.getQName(i); String value = attributes.getValue(i); if (!attrQname.startsWith("xmlns")) { element.setAttributeNS(attrUri, attrQname, value); } } element = (Element) parent.appendChild(element); this.elements.add(element); }