本文整理汇总了Java中org.w3c.dom.Element.removeAttributeNS方法的典型用法代码示例。如果您正苦于以下问题:Java Element.removeAttributeNS方法的具体用法?Java Element.removeAttributeNS怎么用?Java Element.removeAttributeNS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Element
的用法示例。
在下文中一共展示了Element.removeAttributeNS方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: namespace
import org.w3c.dom.Element; //导入方法依赖的package包/类
protected void namespace(Element element, String prefix, String uri) {
String qname;
if ("".equals(prefix) || prefix == null) {
qname = "xmlns";
} else {
qname = "xmlns:" + prefix;
}
// older version of Xerces (I confirmed that the bug is gone with Xerces 2.4.0)
// have a problem of re-setting the same namespace attribute twice.
// work around this bug removing it first.
if (element.hasAttributeNS("http://www.w3.org/2000/xmlns/", qname)) {
// further workaround for an old Crimson bug where the removeAttribtueNS
// method throws NPE when the element doesn't have any attribute.
// to be on the safe side, check the existence of attributes before
// attempting to remove it.
// for details about this bug, see org.apache.crimson.tree.ElementNode2
// line 540 or the following message:
// https://jaxb.dev.java.net/servlets/ReadMsg?list=users&msgNo=2767
element.removeAttributeNS("http://www.w3.org/2000/xmlns/", qname);
}
// workaround until here
element.setAttributeNS("http://www.w3.org/2000/xmlns/", qname, uri);
}
示例2: relativizeElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
protected static void relativizeElement(Element e) {
// work from leaves to root in each subtree
final NodeList children = e.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
final Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE)
relativizeElement((Element) n);
}
// relativize the xlink:href attribute if there is one
if (e.hasAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI, "href")) {
try {
final URL url = new URL(new URL(e.getBaseURI()),
XLinkSupport.getXLinkHref(e));
final String anchor = url.getRef();
final String name = new File(url.getPath()).getName();
XLinkSupport.setXLinkHref(e, name + '#' + anchor);
}
// FIXME: review error message
catch (MalformedURLException ex) {
// ErrorLog.warn(ex);
}
}
// remove xml:base attribute if there is one
e.removeAttributeNS(XMLSupport.XML_NAMESPACE_URI, "base");
}
示例3: testRemoveAttributeNS
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testRemoveAttributeNS() throws Exception {
final String nsURI = "urn:BooksAreUs.org:BookInfo";
final String localName = "category";
Document document = createDOMWithNS("ElementSample01.xml");
Element elemNode = (Element) document.getElementsByTagName("book").item(0);
elemNode.removeAttributeNS(nsURI, localName);
assertNull(elemNode.getAttributeNodeNS(nsURI, localName));
}
示例4: removeXmlBase
import org.w3c.dom.Element; //导入方法依赖的package包/类
private static void removeXmlBase(Element e) {
e.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "base"); // NOI18N
e.removeAttribute("xml:base"); // NOI18N
}
示例5: cleanToolsReferences
import org.w3c.dom.Element; //导入方法依赖的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;
}