本文整理匯總了Java中org.w3c.dom.NamedNodeMap.getNamedItemNS方法的典型用法代碼示例。如果您正苦於以下問題:Java NamedNodeMap.getNamedItemNS方法的具體用法?Java NamedNodeMap.getNamedItemNS怎麽用?Java NamedNodeMap.getNamedItemNS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.NamedNodeMap
的用法示例。
在下文中一共展示了NamedNodeMap.getNamedItemNS方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compareElementAttrs
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
private static boolean compareElementAttrs(Element e1, Element e2) {
NamedNodeMap at1 = e1.getAttributes();
NamedNodeMap at2 = e2.getAttributes();
if (at1.getLength() != at2.getLength()) {
System.out.println("Different number of attributes");
}
for (int i = 0; i < at1.getLength(); i++) {
Attr attr1 = (Attr)at1.item(i);
Attr attr2 = (Attr)at2.getNamedItemNS(attr1.getNamespaceURI(), attr1.getLocalName());
if (attr2 == null) {
System.out.println("Attribute " + attr1.getNodeName() + " not found");
return false;
}
if (!compareStrings(attr1.getNodeValue(), attr2.getNodeValue())) {
System.out.println("Different attributes " + attr1.getNodeName() + " and " + attr2.getNodeName());
return false;
}
}
return true;
}
示例2: hasOverrideOrRemoveTag
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
* Checks whether the given element has a tools:merge=override or tools:merge=remove attribute.
* @param node The node to check.
* @return True if the element has a tools:merge=override or tools:merge=remove attribute.
*/
private boolean hasOverrideOrRemoveTag(@Nullable Node node) {
if (node == null || node.getNodeType() != Node.ELEMENT_NODE) {
return false;
}
NamedNodeMap attrs = node.getAttributes();
Node merge = attrs.getNamedItemNS(TOOLS_URI, MERGE_ATTR);
String value = merge == null ? null : merge.getNodeValue();
return MERGE_OVERRIDE.equals(value) || MERGE_REMOVE.equals(value);
}
示例3: ensureRepositoryIsStarted
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
@Test
public void ensureRepositoryIsStarted() throws Exception {
try ( CloseableHttpClient client = newClient() ) {
HttpGet get = new HttpGet("http://localhost:" + LAUNCHPAD_PORT + "/server/default/jcr:root");
try ( CloseableHttpResponse response = client.execute(get) ) {
if ( response.getStatusLine().getStatusCode() != 200 ) {
fail("Unexpected status line " + response.getStatusLine());
}
Header contentType = response.getFirstHeader("Content-Type");
assertThat("Content-Type header", contentType.getValue(), equalTo("text/xml"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(response.getEntity().getContent());
Element docElement = document.getDocumentElement();
NamedNodeMap attrs = docElement.getAttributes();
Node nameAttr = attrs.getNamedItemNS("http://www.jcp.org/jcr/sv/1.0", "name");
assertThat("no 'name' attribute found", nameAttr, notNullValue());
assertThat("Invalid name attribute value", nameAttr.getNodeValue(), equalTo("jcr:root"));
}
}
}
示例4: 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");
}
示例5: testGetNamedItemNS
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
@Test
public void testGetNamedItemNS() throws Exception {
Document document = createDOMWithNS("NamedNodeMap03.xml");
NodeList nodeList = document.getElementsByTagName("body");
nodeList = nodeList.item(0).getChildNodes();
Node n = nodeList.item(7);
NamedNodeMap namedNodeMap = n.getAttributes();
Node node = namedNodeMap.getNamedItemNS("urn:BooksAreUs.org:BookInfo", "aaa");
assertEquals(node.getNodeValue(), "value");
}
示例6: getAttributeValueNS
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
* 名前空間を指定してNode內の指定した屬性値を取得する.
* @param node 対象となる要素(Nodeオブジェクト)
* @param name 取得する屬性名
* @param ns 名前空間名
* @return 取得した屬性値
*/
private String getAttributeValueNS(final Node node, final String name, final String ns) {
NamedNodeMap nnm = node.getAttributes();
Node attr = nnm.getNamedItemNS(ns, name);
if (attr != null) {
return attr.getNodeValue();
} else {
return "";
}
}
示例7: queryElements
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
* @semantics Navigates through read-only Node tree to determine context and provide right results.
* @postconditions Let ctx unchanged
* @time Performs fast up to 300 ms.
* @stereotype query
* @param virtualElementCtx represents virtual element Node that has to be replaced, its own attributes does not name sense, it can be used just as the navigation start point.
* @return enumeration of <code>GrammarResult</code>s (ELEMENT_NODEs) that can be queried on name, and attributes.
* Every list member represents one possibility.
*/
@Override
public Enumeration<GrammarResult> queryElements(HintContext virtualElementCtx) {
String start = virtualElementCtx.getCurrentPrefix();
Node parentNode = virtualElementCtx.getParentNode();
boolean hasSchema = false;
if (parentNode != null && schemaDoc != null) {
List<String> parentNames = new ArrayList<String>();
while (parentNode != null & parentNode.getNodeName() != null) {
parentNames.add(0, parentNode.getNodeName());
if (parentNode.getParentNode() == null || parentNode.getParentNode().getNodeName() == null) {
NamedNodeMap nnm = parentNode.getAttributes();
hasSchema = nnm.getNamedItemNS("xsi","schemaLocation") != null;
}
parentNode = parentNode.getParentNode();
}
org.jdom.Element schemaParent = schemaDoc.getRootElement();
Iterator<String> it = parentNames.iterator();
String path = ""; //NOI18N
Vector<GrammarResult> toReturn = new Vector<GrammarResult>();
while (it.hasNext() && schemaParent != null) {
String str = it.next();
path = path + "/" + str; //NOI18N
org.jdom.Element el = findElement(schemaParent, str);
if (!it.hasNext()) {
toReturn.addAll(getDynamicCompletion(path, virtualElementCtx, el));
}
if (el != null) {
String type = el.getAttributeValue("type"); //NOI18N
if (type != null) {
schemaParent = findTypeContent(type, schemaDoc.getRootElement());
if (schemaParent == null) {
System.err.println("no schema parent for " + str + " of type " + el.getAttributeValue("type")); //NOI18N
}
} else {
schemaParent = findNonTypedContent(el);
}
} else {
// System.err.println("cannot find element=" + str); //NOI18N
}
}
if (schemaParent != null && !hasSchema) {
processSequence(start, schemaParent, toReturn);
}
return toReturn.elements();
} else {
return Enumerations.<GrammarResult>empty();
}
}
示例8: cleanToolsReferences
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
private static MergingReport.Result cleanToolsReferences(
Element element,
ILogger logger) {
NamedNodeMap namedNodeMap = element.getAttributes();
if (namedNodeMap != null) {
// make a copy of the original list of attributes as we will remove some during this
// process.
List<Node> attributes = new ArrayList<Node>();
for (int i = 0; i < namedNodeMap.getLength(); i++) {
attributes.add(namedNodeMap.item(i));
}
for (Node attribute : attributes) {
if (SdkConstants.TOOLS_URI.equals(attribute.getNamespaceURI())) {
// we need to special case when the element contained tools:node="remove"
// since it also needs to be deleted unless it had a selector.
// if this is ools:node="removeAll", we always delete the element whether or
// not there is a tools:selector.
boolean hasSelector = namedNodeMap.getNamedItemNS(
SdkConstants.TOOLS_URI, "selector") != null;
if (attribute.getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)
&& (attribute.getNodeValue().equals(REMOVE_ALL_OPERATION_XML_MAME)
|| (attribute.getNodeValue().equals(REMOVE_OPERATION_XML_MAME))
&& !hasSelector)) {
if (element.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
logger.error(null /* Throwable */,
String.format(
"tools:node=\"%1$s\" not allowed on top level %2$s element",
attribute.getNodeValue(),
XmlNode.unwrapName(element)));
return ERROR;
} else {
element.getParentNode().removeChild(element);
}
} else {
// anything else, we just clean the attribute.
element.removeAttributeNS(
attribute.getNamespaceURI(), attribute.getLocalName());
}
}
// this could also be the xmlns:tools declaration.
if (attribute.getNodeName().startsWith(SdkConstants.XMLNS_PREFIX)
&& SdkConstants.TOOLS_URI.equals(attribute.getNodeValue())) {
element.removeAttribute(attribute.getNodeName());
}
}
}
// make a copy of the element children since we will be removing some during
// this process, we don't want side effects.
NodeList childNodes = element.getChildNodes();
ImmutableList.Builder<Element> childElements = ImmutableList.builder();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
childElements.add((Element) node);
}
}
for (Element childElement : childElements.build()) {
if (cleanToolsReferences(childElement, logger) == ERROR) {
return ERROR;
}
}
return MergingReport.Result.SUCCESS;
}
示例9: deserializeObjectType
import org.w3c.dom.NamedNodeMap; //導入方法依賴的package包/類
/**
* Deserializes the objectType element from the given Node to an ObjectType
* object.
*
* @param node Node to be deserialized
* @return ObjectType
*/
protected ObjectType deserializeObjectType(final org.w3c.dom.Node node) {
LOGGER.debug(DESERIALIZE_LOG_PATTERN, Constants.NS_ID_ATTR_OBJECT_TYPE);
NamedNodeMap attrs = node.getAttributes();
org.w3c.dom.Node objectType = attrs.getNamedItemNS(Constants.NS_ID_URL, Constants.NS_ID_ATTR_OBJECT_TYPE);
return Enum.valueOf(ObjectType.class, objectType.getNodeValue().toUpperCase());
}