当前位置: 首页>>代码示例>>Java>>正文


Java NamedNodeMap.getNamedItemNS方法代码示例

本文整理汇总了Java中org.w3c.dom.NamedNodeMap.getNamedItemNS方法的典型用法代码示例。如果您正苦于以下问题:Java NamedNodeMap.getNamedItemNS方法的具体用法?Java NamedNodeMap.getNamedItemNS怎么用?Java NamedNodeMap.getNamedItemNS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.NamedNodeMap的用法示例。


在下文中一共展示了NamedNodeMap.getNamedItemNS方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compareElementAttrs

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
private static boolean compareElementAttrs(Element e1, Element e2) {
    NamedNodeMap at1 = e1.getAttributes();
    NamedNodeMap at2 = e2.getAttributes();
    if (at1.getLength() != at2.getLength()) {
        System.out.println("Different number of attributes");
    }
    for (int i = 0; i < at1.getLength(); i++) {
        Attr attr1 = (Attr)at1.item(i);
        Attr attr2 = (Attr)at2.getNamedItemNS(attr1.getNamespaceURI(), attr1.getLocalName());
        if (attr2 == null) {
            System.out.println("Attribute " + attr1.getNodeName() + " not found");
            return false;
        }
        if (!compareStrings(attr1.getNodeValue(), attr2.getNodeValue())) {
            System.out.println("Different attributes " + attr1.getNodeName() + " and " + attr2.getNodeName());
            return false;
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DOMCompare.java

示例2: hasOverrideOrRemoveTag

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
 * Checks whether the given element has a tools:merge=override or tools:merge=remove attribute.
 * @param node The node to check.
 * @return True if the element has a tools:merge=override or tools:merge=remove attribute.
 */
private boolean hasOverrideOrRemoveTag(@Nullable Node node) {
    if (node == null || node.getNodeType() != Node.ELEMENT_NODE) {
        return false;
    }
    NamedNodeMap attrs = node.getAttributes();
    Node merge = attrs.getNamedItemNS(TOOLS_URI, MERGE_ATTR);
    String value = merge == null ? null : merge.getNodeValue();
    return MERGE_OVERRIDE.equals(value) || MERGE_REMOVE.equals(value);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:15,代码来源:ManifestMerger.java

示例3: ensureRepositoryIsStarted

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
@Test
public void ensureRepositoryIsStarted() throws Exception {
    try ( CloseableHttpClient client = newClient() ) {

        HttpGet get = new HttpGet("http://localhost:" + LAUNCHPAD_PORT + "/server/default/jcr:root");

        try ( CloseableHttpResponse response = client.execute(get) ) {

            if ( response.getStatusLine().getStatusCode() != 200 ) {
                fail("Unexpected status line " + response.getStatusLine());
            }

            Header contentType = response.getFirstHeader("Content-Type");
            assertThat("Content-Type header", contentType.getValue(), equalTo("text/xml"));

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(response.getEntity().getContent());

            Element docElement = document.getDocumentElement();
            NamedNodeMap attrs = docElement.getAttributes();

            Node nameAttr = attrs.getNamedItemNS("http://www.jcp.org/jcr/sv/1.0", "name");
            assertThat("no 'name' attribute found", nameAttr, notNullValue());
            assertThat("Invalid name attribute value", nameAttr.getNodeValue(), equalTo("jcr:root"));
        }
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-starter,代码行数:30,代码来源:SmokeIT.java

示例4: testSetNamedItemNS

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
@Test
public void testSetNamedItemNS() throws Exception {
    final String nsURI = "urn:BooksAreUs.org:BookInfo";
    Document document = createDOMWithNS("NamedNodeMap01.xml");
    NodeList nodeList = document.getElementsByTagName("body");
    nodeList = nodeList.item(0).getChildNodes();
    Node n = nodeList.item(3);

    NamedNodeMap namedNodeMap = n.getAttributes();

    // creating an Attribute using createAttributeNS
    // method having the same namespaceURI
    // and the same qualified name as the existing one in the xml file
    Attr attr = document.createAttributeNS(nsURI, "b:style");
    // setting to a new Value
    attr.setValue("newValue");
    Node replacedAttr = namedNodeMap.setNamedItemNS(attr); // return the replaced attr
    assertEquals(replacedAttr.getNodeValue(), "font-family");
    Node updatedAttr = namedNodeMap.getNamedItemNS(nsURI, "style");
    assertEquals(updatedAttr.getNodeValue(), "newValue");


    // creating a non existing attribute node
    attr = document.createAttributeNS(nsURI, "b:newNode");
    attr.setValue("newValue");

    assertNull(namedNodeMap.setNamedItemNS(attr)); // return null

    // checking if the node could be accessed
    // using the getNamedItemNS method
    Node newAttr = namedNodeMap.getNamedItemNS(nsURI, "newNode");
    assertEquals(newAttr.getNodeValue(), "newValue");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:NamedNodeMapTest.java

示例5: testGetNamedItemNS

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
@Test
public void testGetNamedItemNS() throws Exception {
    Document document = createDOMWithNS("NamedNodeMap03.xml");
    NodeList nodeList = document.getElementsByTagName("body");
    nodeList = nodeList.item(0).getChildNodes();
    Node n = nodeList.item(7);
    NamedNodeMap namedNodeMap = n.getAttributes();
    Node node = namedNodeMap.getNamedItemNS("urn:BooksAreUs.org:BookInfo", "aaa");
    assertEquals(node.getNodeValue(), "value");

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:NamedNodeMapTest.java

示例6: getAttributeValueNS

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
 * 名前空間を指定してNode内の指定した属性値を取得する.
 * @param node 対象となる要素(Nodeオブジェクト)
 * @param name 取得する属性名
 * @param ns 名前空間名
 * @return 取得した属性値
 */
private String getAttributeValueNS(final Node node, final String name, final String ns) {
    NamedNodeMap nnm = node.getAttributes();
    Node attr = nnm.getNamedItemNS(ns, name);
    if (attr != null) {
        return attr.getNodeValue();
    } else {
        return "";
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:17,代码来源:AbstractCase.java

示例7: queryElements

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
     * @semantics Navigates through read-only Node tree to determine context and provide right results.
     * @postconditions Let ctx unchanged
     * @time Performs fast up to 300 ms.
     * @stereotype query
     * @param virtualElementCtx represents virtual element Node that has to be replaced, its own attributes does not name sense, it can be used just as the navigation start point.
     * @return enumeration of <code>GrammarResult</code>s (ELEMENT_NODEs) that can be queried on name, and attributes.
     *         Every list member represents one possibility.
     */
    @Override
    public Enumeration<GrammarResult> queryElements(HintContext virtualElementCtx) {
        String start = virtualElementCtx.getCurrentPrefix();
        
        Node parentNode = virtualElementCtx.getParentNode();
        boolean hasSchema = false;
        if (parentNode != null && schemaDoc != null) {
            List<String> parentNames = new ArrayList<String>();
            while (parentNode != null & parentNode.getNodeName() != null) {
                parentNames.add(0, parentNode.getNodeName());
                if (parentNode.getParentNode() == null || parentNode.getParentNode().getNodeName() == null) {
                    NamedNodeMap nnm = parentNode.getAttributes();
                    hasSchema  = nnm.getNamedItemNS("xsi","schemaLocation") != null;
                }
                parentNode = parentNode.getParentNode();
            }
            org.jdom.Element schemaParent = schemaDoc.getRootElement();
            Iterator<String> it = parentNames.iterator();
            String path = ""; //NOI18N
            Vector<GrammarResult> toReturn = new Vector<GrammarResult>();
            while (it.hasNext() && schemaParent != null) {
                String str = it.next();
                path = path + "/" + str; //NOI18N
                org.jdom.Element el = findElement(schemaParent, str);
                if (!it.hasNext()) {
                    toReturn.addAll(getDynamicCompletion(path, virtualElementCtx, el));
                }
                if (el != null) {
                    String type = el.getAttributeValue("type"); //NOI18N
                    if (type != null) {
                        schemaParent = findTypeContent(type, schemaDoc.getRootElement());
                        if (schemaParent == null) {
                            System.err.println("no schema parent for " + str + " of type " + el.getAttributeValue("type")); //NOI18N
                        }
                    } else {
                        schemaParent = findNonTypedContent(el);
                    }
                } else {
//                    System.err.println("cannot find element=" + str); //NOI18N
                }
            }
            if (schemaParent != null && !hasSchema) {
                processSequence(start, schemaParent, toReturn);
            }
            return toReturn.elements();
        } else {
            return Enumerations.<GrammarResult>empty();
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:AbstractSchemaBasedGrammar.java

示例8: cleanToolsReferences

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
private static MergingReport.Result cleanToolsReferences(
        Element element,
        ILogger logger) {

    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        // make a copy of the original list of attributes as we will remove some during this
        // process.
        List<Node> attributes = new ArrayList<Node>();
        for (int i = 0; i < namedNodeMap.getLength(); i++) {
            attributes.add(namedNodeMap.item(i));
        }
        for (Node attribute : attributes) {
            if (SdkConstants.TOOLS_URI.equals(attribute.getNamespaceURI())) {
                // we need to special case when the element contained tools:node="remove"
                // since it also needs to be deleted unless it had a selector.
                // if this is ools:node="removeAll", we always delete the element whether or
                // not there is a tools:selector.
                boolean hasSelector = namedNodeMap.getNamedItemNS(
                        SdkConstants.TOOLS_URI, "selector") != null;
                if (attribute.getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)
                        && (attribute.getNodeValue().equals(REMOVE_ALL_OPERATION_XML_MAME)
                            || (attribute.getNodeValue().equals(REMOVE_OPERATION_XML_MAME))
                                && !hasSelector)) {

                    if (element.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
                        logger.error(null /* Throwable */,
                                String.format(
                                    "tools:node=\"%1$s\" not allowed on top level %2$s element",
                                    attribute.getNodeValue(),
                                    XmlNode.unwrapName(element)));
                        return ERROR;
                    } else {
                        element.getParentNode().removeChild(element);
                    }
                } else {
                    // anything else, we just clean the attribute.
                    element.removeAttributeNS(
                            attribute.getNamespaceURI(), attribute.getLocalName());
                }
            }
            // this could also be the xmlns:tools declaration.
            if (attribute.getNodeName().startsWith(SdkConstants.XMLNS_PREFIX)
                && SdkConstants.TOOLS_URI.equals(attribute.getNodeValue())) {
                element.removeAttribute(attribute.getNodeName());
            }
        }
    }
    // make a copy of the element children since we will be removing some during
    // this process, we don't want side effects.
    NodeList childNodes = element.getChildNodes();
    ImmutableList.Builder<Element> childElements = ImmutableList.builder();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            childElements.add((Element) node);
        }
    }
    for (Element childElement : childElements.build()) {
        if (cleanToolsReferences(childElement, logger) == ERROR) {
            return ERROR;
        }
    }
    return MergingReport.Result.SUCCESS;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:66,代码来源:ToolsInstructionsCleaner.java

示例9: deserializeObjectType

import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
 * Deserializes the objectType element from the given Node to an ObjectType
 * object.
 *
 * @param node Node to be deserialized
 * @return ObjectType
 */
protected ObjectType deserializeObjectType(final org.w3c.dom.Node node) {
    LOGGER.debug(DESERIALIZE_LOG_PATTERN, Constants.NS_ID_ATTR_OBJECT_TYPE);
    NamedNodeMap attrs = node.getAttributes();
    org.w3c.dom.Node objectType = attrs.getNamedItemNS(Constants.NS_ID_URL, Constants.NS_ID_ATTR_OBJECT_TYPE);
    return Enum.valueOf(ObjectType.class, objectType.getNodeValue().toUpperCase());
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:14,代码来源:AbstractHeaderDeserializer.java


注:本文中的org.w3c.dom.NamedNodeMap.getNamedItemNS方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。