Search in sources :

Example 41 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 42 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 43 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 44 with Attr

use of org.w3c.dom.Attr in project orientdb by orientechnologies.

the class OXmlExtractor method xml2doc.

private Object xml2doc(final Node xmlDocument, final String iPath, final int iLevel) {
    final ODocument doc = new ODocument();
    Object result = doc;
    final NamedNodeMap attrs = xmlDocument.getAttributes();
    if (attrs != null)
        for (int i = 0; i < attrs.getLength(); ++i) {
            final Node item = attrs.item(i);
            switch(item.getNodeType()) {
                case Node.ATTRIBUTE_NODE:
                    {
                        final Attr attr = (Attr) item;
                        doc.field(attr.getName(), attr.getValue());
                        break;
                    }
            }
        }
    final NodeList children = xmlDocument.getChildNodes();
    if (children != null) {
        for (int i = 0; i < children.getLength(); ++i) {
            final Node child = children.item(i);
            switch(child.getNodeType()) {
                case Node.ELEMENT_NODE:
                    {
                        final Element element = (Element) child;
                        final String path = iPath.isEmpty() ? element.getNodeName() : iPath + "." + element.getNodeName();
                        if (tagsAsAttribute.contains(iPath)) {
                            final NodeList subChildren = element.getChildNodes();
                            if (subChildren.getLength() > 0) {
                                final Node fieldContent = subChildren.item(0);
                                doc.field(element.getNodeName(), fieldContent.getTextContent());
                            }
                        } else {
                            final Object sub = xml2doc(element, path, iLevel + 1);
                            final Object previous = doc.field(element.getNodeName());
                            if (previous != null) {
                                List list;
                                if (previous instanceof List) {
                                    list = (List) previous;
                                } else {
                                    // TRANSFORM IN A LIST
                                    list = new ArrayList();
                                    list.add(previous);
                                    doc.field(element.getNodeName(), list, OType.EMBEDDEDLIST);
                                }
                                list.add(sub);
                            } else
                                doc.field(element.getNodeName(), sub, OType.EMBEDDED);
                            if (rootNode != null && rootNode.startsWith(path))
                                // SKIP
                                result = doc.field(element.getNodeName());
                        }
                        break;
                    }
            }
        }
    }
    return result;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Attr(org.w3c.dom.Attr) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 45 with Attr

use of org.w3c.dom.Attr in project midpoint by Evolveum.

the class DomLexicalProcessor method parseElementContentToMap.

private MapXNode parseElementContentToMap(Element element) throws SchemaException {
    MapXNode xmap = new MapXNode();
    // Attributes
    for (Attr attr : DOMUtil.listApplicationAttributes(element)) {
        QName attrQName = DOMUtil.getQName(attr);
        XNode subnode = parseAttributeValue(attr);
        xmap.put(attrQName, subnode);
    }
    // Sub-elements
    QName lastElementQName = null;
    List<Element> lastElements = null;
    for (Element childElement : DOMUtil.listChildElements(element)) {
        QName childQName = DOMUtil.getQName(childElement);
        if (match(childQName, lastElementQName)) {
            lastElements.add(childElement);
        } else {
            parseSubElementsGroupAsMapEntry(xmap, lastElementQName, lastElements);
            lastElementQName = childQName;
            lastElements = new ArrayList<>();
            lastElements.add(childElement);
        }
    }
    parseSubElementsGroupAsMapEntry(xmap, lastElementQName, lastElements);
    return xmap;
}
Also used : QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6