本文整理汇总了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");
}
示例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;
}