本文整理匯總了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;
}