当前位置: 首页>>代码示例>>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;未经允许,请勿转载。