org.w3c.dom.Attr#getPrefix ( )源码实例Demo

下面列出了org.w3c.dom.Attr#getPrefix ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: DOMPrinter.java
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
源代码2 项目: openjdk-jdk9   文件: DOMPrinter.java
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
源代码3 项目: TencentKona-8   文件: DOMPrinter.java
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
源代码4 项目: openjdk-8-source   文件: DOMPrinter.java
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
源代码5 项目: jdk8u60   文件: DOMPrinter.java
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
源代码6 项目: groovy   文件: DomToGroovy.java
protected boolean printAttributeWithoutPrefix(Attr attribute, boolean hasAttribute) {
    String prefix = attribute.getPrefix();
    if (prefix == null || prefix.length() == 0) {
        if (!hasAttribute) {
            hasAttribute = true;
        } else {
            print(", ");
        }
        String localName = getLocalName(attribute);
        boolean needsEscaping = checkEscaping(localName);
        if (needsEscaping) print(qt);
        print(localName);
        if (needsEscaping) print(qt);
        print(":");
        printQuoted(getAttributeValue(attribute));
    }
    return hasAttribute;
}
 
源代码7 项目: openjdk-jdk8u   文件: DOMXPathTransform.java
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: DOMPrinter.java
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
源代码9 项目: openjdk-8-source   文件: DOMXPathTransform.java
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
源代码10 项目: java-client-api   文件: DOMWriter.java
public void serializeAttributes(NamedNodeMap attributes) throws XMLStreamException {
  for (int i=0; i < attributes.getLength(); i++) {
    Attr attribute = (Attr) attributes.item(i);
    String namespaceURI = attribute.getNamespaceURI();
    String prefix       = (namespaceURI != null) ? attribute.getPrefix() : null;
    String localName    = (namespaceURI != null) ? attribute.getLocalName() : attribute.getName();
    String value        = attribute.getValue();
    if ("http://www.w3.org/2000/xmlns/".equals(namespaceURI)) {
      //TODO: Seems there should be a better way to prevent redundant namespaces.
    } else if (prefix != null) {
      serializer.writeAttribute(prefix, namespaceURI, localName, value);
    } else if (namespaceURI != null) {
      serializer.writeAttribute(namespaceURI, localName, value);
    } else {
      serializer.writeAttribute(localName, value);
    }
  }
}
 
源代码11 项目: teamengine   文件: DomUtils.java
static public Map<QName, String> getAttributes(Node node) {
    Map<QName, String> atts = new HashMap<QName, String>();
    NamedNodeMap nnm = node.getAttributes();
    if (nnm != null) {
        for (int i = 0; i < nnm.getLength(); i++) {
            Attr att = (Attr) nnm.item(i);
            String uri = att.getBaseURI();
            String localname = att.getLocalName();
            String prefix = att.getPrefix();
            QName name;
            if (uri == null) {
                name = new QName(localname);
            } else if (prefix == null) {
                name = new QName(uri, localname);
            } else {
                name = new QName(uri, localname, prefix);
            }
            if (prefix == null
                    || !(prefix.equals("xmlns") || prefix.equals("xml"))) {
                atts.put(name, att.getValue());
            }
        }
    }
    return atts;
}
 
源代码12 项目: openjdk-jdk9   文件: DOMXPathTransform.java
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
源代码13 项目: jdk8u_jdk   文件: DOMXPathTransform.java
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
源代码14 项目: cxf   文件: AbstractBPBeanDefinitionParser.java
protected boolean parseAttributes(Element element, ParserContext ctx, MutableBeanMetadata bean) {
    NamedNodeMap atts = element.getAttributes();
    boolean setBus = false;
    for (int i = 0; i < atts.getLength(); i++) {
        Attr node = (Attr) atts.item(i);
        String val = node.getValue();
        String pre = node.getPrefix();
        String name = node.getLocalName();
        String prefix = node.getPrefix();

        // Don't process namespaces
        if (isNamespace(name, prefix)) {
            continue;
        }

        if ("createdFromAPI".equals(name) || "abstract".equals(name)) {
            bean.setScope(BeanMetadata.SCOPE_PROTOTYPE);
        } else {
            if ("depends-on".equals(name)) {
                bean.addDependsOn(val);
            } else if ("name".equals(name)) {
                processNameAttribute(element, ctx, bean, val);
            } else if ("bus".equals(name)) {
                processBusAttribute(element, ctx, bean, val);
            } else if (!"id".equals(name) && isAttribute(pre, name)) {
                mapAttribute(bean, element, name, val, ctx);
            }
        }
    }
    return setBus; // 'setBus' is always false
}
 
源代码15 项目: cxf   文件: W3CDOMStreamReader.java
public QName getAttributeName(int i) {
    Attr at = getAttribute(i);

    String prefix = at.getPrefix();
    String ln = getLocalName(at);
    // at.getNodeName();
    String ns = at.getNamespaceURI();

    if (prefix == null) {
        return new QName(ns, ln);
    }
    return new QName(ns, ln, prefix);
}
 
源代码16 项目: openjdk-8   文件: DOMXPathFilter2Transform.java
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
源代码17 项目: hottub   文件: DOMXPathFilter2Transform.java
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
源代码18 项目: jdk8u60   文件: DOMXPathFilter2Transform.java
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
源代码19 项目: openjdk-jdk8u   文件: DOMXPathFilter2Transform.java
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
源代码20 项目: xcurator   文件: XMLUtils.java
/**
 * Check if the attribute node is a namespace definition.
 *
 * @param attr
 * @return
 */
public static boolean isNamespaceDef(Attr attr) {
    String prefix = attr.getPrefix();
    return (prefix != null && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
            || attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE);
}