當前位置: 首頁>>代碼示例>>Java>>正文


Java NamedNodeMap.setNamedItemNS方法代碼示例

本文整理匯總了Java中org.w3c.dom.NamedNodeMap.setNamedItemNS方法的典型用法代碼示例。如果您正苦於以下問題:Java NamedNodeMap.setNamedItemNS方法的具體用法?Java NamedNodeMap.setNamedItemNS怎麽用?Java NamedNodeMap.setNamedItemNS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.NamedNodeMap的用法示例。


在下文中一共展示了NamedNodeMap.setNamedItemNS方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: synchronizeData

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/** Synchronizes the data (name and value) for fast nodes. */
protected final void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff data
    DeferredDocumentImpl ownerDocument =
        (DeferredDocumentImpl) this.ownerDocument;

    // we don't want to generate any event for this so turn them off
    boolean orig = ownerDocument.mutationEvents;
    ownerDocument.mutationEvents = false;

    name = ownerDocument.getNodeName(fNodeIndex);

    // extract local part from QName
    int index = name.indexOf(':');
    if (index < 0) {
        localName = name;
    }
    else {
        localName = name.substring(index + 1);
    }

        namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
    type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);

    // attributes
    setupDefaultAttributes();
    int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
    if (attrIndex != -1) {
        NamedNodeMap attrs = getAttributes();
        boolean seenSchemaDefault = false;
        do {
            AttrImpl attr = (AttrImpl) ownerDocument.getNodeObject(attrIndex);
            // Take special care of schema defaulted attributes. Calling the
            // non-namespace aware setAttributeNode() method could overwrite
            // another attribute with the same local name.
            if (!attr.getSpecified() && (seenSchemaDefault ||
                (attr.getNamespaceURI() != null &&
                attr.getNamespaceURI() != NamespaceContext.XMLNS_URI &&
                attr.getName().indexOf(':') < 0))) {
                seenSchemaDefault = true;
                attrs.setNamedItemNS(attr);
            }
            else {
                attrs.setNamedItem(attr);
            }
            attrIndex = ownerDocument.getPrevSibling(attrIndex);
        } while (attrIndex != -1);
    }

    // set mutation events flag back to its original value
    ownerDocument.mutationEvents = orig;

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:58,代碼來源:DeferredElementNSImpl.java


注:本文中的org.w3c.dom.NamedNodeMap.setNamedItemNS方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。