本文整理汇总了Java中org.w3c.dom.Attr.getNamespaceURI方法的典型用法代码示例。如果您正苦于以下问题:Java Attr.getNamespaceURI方法的具体用法?Java Attr.getNamespaceURI怎么用?Java Attr.getNamespaceURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Attr
的用法示例。
在下文中一共展示了Attr.getNamespaceURI方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeURIs
import org.w3c.dom.Attr; //导入方法依赖的package包/类
public void serializeURIs(Object element, XMLSerializer target) {
NamedNodeMap al = ((Element)element).getAttributes();
int len = al.getLength();
NamespaceContext2 context = target.getNamespaceContext();
for( int i=0; i<len; i++ ) {
Attr a = (Attr)al.item(i);
if ("xmlns".equals(a.getPrefix())) {
context.force(a.getValue(), a.getLocalName());
continue;
}
if ("xmlns".equals(a.getName())) {
if (element instanceof org.w3c.dom.Element) {
context.declareNamespace(a.getValue(), null, false);
continue;
} else {
context.force(a.getValue(), "");
continue;
}
}
String nsUri = a.getNamespaceURI();
if(nsUri!=null && nsUri.length()>0)
context.declareNamespace( nsUri, a.getPrefix(), true );
}
}
示例2: storeAttribute
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* This method looks at an attribute and stores it, if it is a namespace
* attribute.
*
* @param attribute
* to examine
*/
private void storeAttribute(Attr attribute) {
// examine the attributes in namespace xmlns
if (attribute.getNamespaceURI() != null
&& attribute.getNamespaceURI().equals(
XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
// Default namespace xmlns="uri goes here"
if (attribute.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE)) {
putInCache(DEFAULT_NS, attribute.getNodeValue());
} else {
// Here are the defined prefixes stored
putInCache(attribute.getLocalName(), attribute.getNodeValue());
}
}
}
示例3: duplicateNode
import org.w3c.dom.Attr; //导入方法依赖的package包/类
static Node duplicateNode(Document document, Node node) {
Node newNode;
if (node.getNamespaceURI() != null) {
newNode = document.createElementNS(node.getNamespaceURI(), node.getLocalName());
} else {
newNode = document.createElement(node.getNodeName());
}
// copy the attributes
NamedNodeMap attributes = node.getAttributes();
for (int i = 0 ; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
Attr newAttr;
if (attr.getNamespaceURI() != null) {
newAttr = document.createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
newNode.getAttributes().setNamedItemNS(newAttr);
} else {
newAttr = document.createAttribute(attr.getName());
newNode.getAttributes().setNamedItem(newAttr);
}
newAttr.setValue(attr.getValue());
}
// then duplicate the sub-nodes.
NodeList children = node.getChildNodes();
for (int i = 0 ; i < children.getLength() ; i++) {
Node child = children.item(i);
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Node duplicatedChild = duplicateNode(document, child);
newNode.appendChild(duplicatedChild);
}
return newNode;
}
示例4: run
import org.w3c.dom.Attr; //导入方法依赖的package包/类
public void run() {
Set<String> declaredPrefixes = new HashSet<String>();
for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
NamedNodeMap atts = n.getAttributes();
if(atts==null) continue; // broken DOM. but be graceful.
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
String nsUri = a.getNamespaceURI();
if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
continue; // not a namespace declaration
String prefix = a.getLocalName();
if(prefix==null)
continue; // broken DOM. skip to be safe
if(prefix.equals("xmlns")) {
prefix = "";
}
String value = a.getValue();
if(value==null)
continue; // broken DOM. skip to be safe
if(declaredPrefixes.add(prefix)) {
serializer.addInscopeBinding(value,prefix);
}
}
}
}
示例5: serializeAttributes
import org.w3c.dom.Attr; //导入方法依赖的package包/类
public void serializeAttributes(Object element, XMLSerializer target) throws SAXException {
NamedNodeMap al = ((Element)element).getAttributes();
int len = al.getLength();
for( int i=0; i<len; i++ ) {
Attr a = (Attr)al.item(i);
// work defensively
String uri = a.getNamespaceURI();
if(uri==null) uri="";
String local = a.getLocalName();
String name = a.getName();
if(local==null) local = name;
if (uri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE) && ("nil".equals(local))) {
isNilIncluded = true;
}
if(name.startsWith("xmlns")) continue;// DOM reports ns decls as attributes
target.attribute(uri,local,a.getValue());
}
}
示例6: validate
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Validates attributes of a <jaxb:bindings> element.
*/
private void validate( Element bindings ) {
NamedNodeMap atts = bindings.getAttributes();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if( a.getNamespaceURI()!=null )
continue; // all foreign namespace OK.
if( a.getLocalName().equals("node") )
continue;
if( a.getLocalName().equals("schemaLocation"))
continue;
if( a.getLocalName().equals("scd") )
continue;
// enhancements
if( a.getLocalName().equals("required") ) //
continue;
if( a.getLocalName().equals("multiple") ) //
continue;
// TODO: flag error for this undefined attribute
}
}
示例7: fixupAttrsSingle
import org.w3c.dom.Attr; //导入方法依赖的package包/类
private static void fixupAttrsSingle(Element e) throws DOMException {
removeXmlBase(e);
Map<String, String> replace = new HashMap<String, String>();
NamedNodeMap attrs = e.getAttributes();
for (int j = 0; j < attrs.getLength(); j++) {
Attr attr = (Attr) attrs.item(j);
if (attr.getNamespaceURI() == null && !attr.getName().equals("xmlns")) { // NOI18N
replace.put(attr.getName(), attr.getValue());
}
}
for (Map.Entry<String, String> entry : replace.entrySet()) {
e.removeAttribute(entry.getKey());
e.setAttributeNS(null, entry.getKey(), entry.getValue());
}
}
示例8: initNamespaceSupport
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Initialize namespace support by collecting all of the namespace
* declarations in the root's ancestors. This is necessary to
* support schemas fragments, i.e. schemas embedded in other
* documents. See,
*
* https://jaxp.dev.java.net/issues/show_bug.cgi?id=43
*
* Requires the DOM to be created with namespace support enabled.
*/
private void initNamespaceSupport(Element schemaRoot) {
fNamespaceSupport = new SchemaNamespaceSupport();
fNamespaceSupport.reset();
Node parent = schemaRoot.getParentNode();
while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE
&& !parent.getNodeName().equals("DOCUMENT_NODE"))
{
Element eparent = (Element) parent;
NamedNodeMap map = eparent.getAttributes();
int length = (map != null) ? map.getLength() : 0;
for (int i = 0; i < length; i++) {
Attr attr = (Attr) map.item(i);
String uri = attr.getNamespaceURI();
// Check if attribute is an ns decl -- requires ns support
if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) {
String prefix = attr.getLocalName().intern();
if (prefix == "xmlns") prefix = "";
// Declare prefix if not set -- moving upwards
if (fNamespaceSupport.getURI(prefix) == null) {
fNamespaceSupport.declarePrefix(prefix,
attr.getValue().intern());
}
}
}
parent = parent.getParentNode();
}
}
示例9: compare
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Compares two attributes based on the C14n specification.
*
* <UL>
* <LI>Namespace nodes have a lesser document order position than
* attribute nodes.
* <LI> An element's namespace nodes are sorted lexicographically by
* local name (the default namespace node, if one exists, has no
* local name and is therefore lexicographically least).
* <LI> An element's attribute nodes are sorted lexicographically with
* namespace URI as the primary key and local name as the secondary
* key (an empty namespace URI is lexicographically least).
* </UL>
*
* @param attr0
* @param attr1
* @return returns a negative integer, zero, or a positive integer as
* obj0 is less than, equal to, or greater than obj1
*
*/
public int compare(Attr attr0, Attr attr1) {
String namespaceURI0 = attr0.getNamespaceURI();
String namespaceURI1 = attr1.getNamespaceURI();
boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);
if (isNamespaceAttr0) {
if (isNamespaceAttr1) {
// both are namespaces
String localname0 = attr0.getLocalName();
String localname1 = attr1.getLocalName();
if ("xmlns".equals(localname0)) {
localname0 = "";
}
if ("xmlns".equals(localname1)) {
localname1 = "";
}
return localname0.compareTo(localname1);
}
// attr0 is a namespace, attr1 is not
return ATTR0_BEFORE_ATTR1;
} else if (isNamespaceAttr1) {
// attr1 is a namespace, attr0 is not
return ATTR1_BEFORE_ATTR0;
}
// none is a namespace
if (namespaceURI0 == null) {
if (namespaceURI1 == null) {
String name0 = attr0.getName();
String name1 = attr1.getName();
return name0.compareTo(name1);
}
return ATTR0_BEFORE_ATTR1;
} else if (namespaceURI1 == null) {
return ATTR1_BEFORE_ATTR0;
}
int a = namespaceURI0.compareTo(namespaceURI1);
if (a != 0) {
return a;
}
return (attr0.getLocalName()).compareTo(attr1.getLocalName());
}
示例10: handleAttributesSubtree
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well --
* subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
// It's not a namespace attr node. Add to the result and continue.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
// The default mapping for xml must not be output.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
// Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
}
if (firstCall) {
// It is the first node of the subtree
// Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result);
// output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall = false;
}
return result.iterator();
}
示例11: handleAttributesSubtree
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
//It's not a namespace attr node. Add to the result and continue.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
//The default mapping for xml must not be output.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
//Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
}
if (firstCall) {
//It is the first node of the subtree
//Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result);
//output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall = false;
}
return result.iterator();
}