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


Java NamedNodeMap.setNamedItem方法代碼示例

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


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

示例1: testSetNamedItem

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
@Test
public void testSetNamedItem() throws Exception {
    Document document = createDOMWithNS("NamedNodeMap03.xml");
    NodeList nodeList = document.getElementsByTagName("body");
    nodeList = nodeList.item(0).getChildNodes();
    Node n = nodeList.item(1);

    NamedNodeMap namedNodeMap = n.getAttributes();
    Attr attr = document.createAttribute("name");
    Node replacedAttr = namedNodeMap.setNamedItem(attr);
    assertEquals(replacedAttr.getNodeValue(), "attributeValue");
    Node updatedAttrNode = namedNodeMap.getNamedItem("name");
    assertEquals(updatedAttrNode.getNodeValue(), "");

    Attr newAttr = document.createAttribute("nonExistingName");
    assertNull(namedNodeMap.setNamedItem(newAttr));
    Node newAttrNode = namedNodeMap.getNamedItem("nonExistingName");
    assertEquals(newAttrNode.getNodeValue(), "");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源: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);

    // attributes
    setupDefaultAttributes();
    int index = ownerDocument.getNodeExtra(fNodeIndex);
    if (index != -1) {
        NamedNodeMap attrs = getAttributes();
        do {
            NodeImpl attr = (NodeImpl)ownerDocument.getNodeObject(index);
            attrs.setNamedItem(attr);
            index = ownerDocument.getPrevSibling(index);
        } while (index != -1);
    }

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

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

示例3: doctypeDecl

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:36,代碼來源:DOMResultBuilder.java

示例4: setAttribute

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public static void setAttribute(Node node, String attName, String val) {
    NamedNodeMap attributes=node.getAttributes();
    Node attNode=node.getOwnerDocument().createAttribute(attName);
    attNode.setNodeValue( val );
    attributes.setNamedItem(attNode);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:7,代碼來源:DomUtil.java

示例5: notationDecl

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
 * A notation declaration
 *
 * @param name     The name of the notation.
 * @param identifier    An object containing all location information
 *                      pertinent to this notation.
 * @param augs Additional information that may include infoset
 *                      augmentations.
 *
 * @throws XNIException Thrown by handler to signal an error.
 */
public void notationDecl (String name, XMLResourceIdentifier identifier,
Augmentations augs) throws XNIException {

    // internal subset string
    String publicId = identifier.getPublicId ();
    String literalSystemId = identifier.getLiteralSystemId ();
    if (fInternalSubset != null && !fInDTDExternalSubset) {
        fInternalSubset.append ("<!NOTATION ");
        fInternalSubset.append (name);
        if (publicId != null) {
            fInternalSubset.append (" PUBLIC '");
            fInternalSubset.append (publicId);
            if (literalSystemId != null) {
                fInternalSubset.append ("' '");
                fInternalSubset.append (literalSystemId);
            }
        }
        else {
            fInternalSubset.append (" SYSTEM '");
            fInternalSubset.append (literalSystemId);
        }
        fInternalSubset.append ("'>\n");
    }

    // NOTE: We only know how to create these nodes for the Xerces
    //       DOM implementation because DOM Level 2 does not specify
    //       that functionality. -Ac

    // create full node
    if (fDocumentImpl !=null && fDocumentType != null) {
        NamedNodeMap notations = fDocumentType.getNotations ();
        if (notations.getNamedItem (name) == null) {
            NotationImpl notation = (NotationImpl)fDocumentImpl.createNotation (name);
            notation.setPublicId (publicId);
            notation.setSystemId (literalSystemId);
            notation.setBaseURI (identifier.getBaseSystemId ());
            notations.setNamedItem (notation);
        }
    }

    // create deferred node
    if (fDocumentTypeIndex != -1) {
        boolean found = false;
        int nodeIndex = fDeferredDocumentImpl.getLastChild (fDocumentTypeIndex, false);
        while (nodeIndex != -1) {
            short nodeType = fDeferredDocumentImpl.getNodeType (nodeIndex, false);
            if (nodeType == Node.NOTATION_NODE) {
                String nodeName = fDeferredDocumentImpl.getNodeName (nodeIndex, false);
                if (nodeName.equals (name)) {
                    found = true;
                    break;
                }
            }
            nodeIndex = fDeferredDocumentImpl.getPrevSibling (nodeIndex, false);
        }
        if (!found) {
            int notationIndex = fDeferredDocumentImpl.createDeferredNotation (
            name, publicId, literalSystemId, identifier.getBaseSystemId ());
            fDeferredDocumentImpl.appendChild (fDocumentTypeIndex, notationIndex);
        }
    }

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

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

示例7: setAttribute

import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
public static void setAttribute(Node node, String attName, String val) {
	NamedNodeMap attributes = node.getAttributes();
	Node attNode = node.getOwnerDocument().createAttribute(attName);
	attNode.setNodeValue(val);
	attributes.setNamedItem(attNode);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:7,代碼來源:DomUtil.java


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