Search in sources :

Example 6 with Attr

use of org.w3c.dom.Attr in project hackpad by dropbox.

the class XmlNode method deleteMe.

void deleteMe() {
    if (dom instanceof Attr) {
        Attr attr = (Attr) this.dom;
        attr.getOwnerElement().getAttributes().removeNamedItemNS(attr.getNamespaceURI(), attr.getLocalName());
    } else {
        if (this.dom.getParentNode() != null) {
            this.dom.getParentNode().removeChild(this.dom);
        } else {
        //    This case can be exercised at least when executing the regression
        //    tests under https://bugzilla.mozilla.org/show_bug.cgi?id=354145
        }
    }
}
Also used : Attr(org.w3c.dom.Attr)

Example 7 with Attr

use of org.w3c.dom.Attr in project che by eclipse.

the class Element method createAttrNSNode.

private Attr createAttrNSNode(NewAttribute attribute) {
    if (attribute.getPrefix().equals(XMLNS_ATTRIBUTE)) {
        final Attr attr = document().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, attribute.getName());
        attr.setValue(attribute.getValue());
        //save uri
        xmlTree.putNamespace(attribute.getLocalName(), attribute.getValue());
        return attr;
    } else {
        //retrieve namespace
        final String uri = xmlTree.getNamespaceUri(attribute.getPrefix());
        final Attr attr = document().createAttributeNS(uri, attribute.getName());
        attr.setValue(attribute.getValue());
        return attr;
    }
}
Also used : Attr(org.w3c.dom.Attr)

Example 8 with Attr

use of org.w3c.dom.Attr in project che by eclipse.

the class RefactoringSessionTransformer method createArgument.

/**
	 * Creates a refactoring argument with the specified name and value.
	 * <p>
	 * If no refactoring is currently processed, this call has no effect.
	 * </p>
	 *
	 * @param name
	 *            the non-empty name of the argument
	 * @param value
	 *            the value of the argument
	 *
	 * @throws CoreException
	 *             if an error occurs while creating a new argument
	 */
public void createArgument(final String name, final String value) throws CoreException {
    Assert.isNotNull(name);
    //$NON-NLS-1$
    Assert.isTrue(!"".equals(name));
    Assert.isNotNull(value);
    if (fDocument != null && fRefactoringArguments != null && value != null) {
        try {
            final Attr attribute = fDocument.createAttribute(name);
            attribute.setValue(value);
            fRefactoringArguments.add(attribute);
        } catch (DOMException exception) {
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, exception.getLocalizedMessage(), null));
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) DOMException(org.w3c.dom.DOMException) CoreException(org.eclipse.core.runtime.CoreException) Attr(org.w3c.dom.Attr)

Example 9 with Attr

use of org.w3c.dom.Attr in project SmartAndroidSource by jaychou2012.

the class XmlDom method serialize.

private void serialize(Element e, XmlSerializer s, int depth, String spaces) throws Exception {
    String name = e.getTagName();
    writeSpace(s, depth, spaces);
    s.startTag("", name);
    if (e.hasAttributes()) {
        NamedNodeMap nm = e.getAttributes();
        for (int i = 0; i < nm.getLength(); i++) {
            Attr attr = (Attr) nm.item(i);
            s.attribute("", attr.getName(), attr.getValue());
        }
    }
    if (e.hasChildNodes()) {
        NodeList nl = e.getChildNodes();
        int elements = 0;
        for (int i = 0; i < nl.getLength(); i++) {
            Node n = nl.item(i);
            short type = n.getNodeType();
            switch(type) {
                case Node.ELEMENT_NODE:
                    serialize((Element) n, s, depth + 1, spaces);
                    elements++;
                    break;
                case Node.TEXT_NODE:
                    s.text(text(n));
                    break;
                case Node.CDATA_SECTION_NODE:
                    s.cdsect(text(n));
                    break;
            }
        }
        if (elements > 0) {
            writeSpace(s, depth, spaces);
        }
    }
    s.endTag("", name);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Attr(org.w3c.dom.Attr)

Example 10 with Attr

use of org.w3c.dom.Attr in project qksms by moezbhatti.

the class SmilXmlSerializer method writeElement.

private static void writeElement(Writer writer, Element element) throws IOException {
    writer.write('<');
    writer.write(element.getTagName());
    if (element.hasAttributes()) {
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Attr attribute = (Attr) attributes.item(i);
            writer.write(" " + attribute.getName());
            writer.write("=\"" + attribute.getValue() + "\"");
        }
    }
    // FIXME: Might throw ClassCastException
    SMILElement childElement = (SMILElement) element.getFirstChild();
    if (childElement != null) {
        writer.write('>');
        do {
            writeElement(writer, childElement);
            childElement = (SMILElement) childElement.getNextSibling();
        } while (childElement != null);
        writer.write("</");
        writer.write(element.getTagName());
        writer.write('>');
    } else {
        writer.write("/>");
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) SMILElement(org.w3c.dom.smil.SMILElement) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)385 Element (org.w3c.dom.Element)178 NamedNodeMap (org.w3c.dom.NamedNodeMap)160 Document (org.w3c.dom.Document)134 Node (org.w3c.dom.Node)126 NodeList (org.w3c.dom.NodeList)80 DOMException (org.w3c.dom.DOMException)30 ArrayList (java.util.ArrayList)25 DocumentBuilder (javax.xml.parsers.DocumentBuilder)16 HashMap (java.util.HashMap)12 Text (org.w3c.dom.Text)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 QName (javax.xml.namespace.QName)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)7 ParseException (java.text.ParseException)6 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)6