Java Code Examples for javax.xml.XMLConstants#XMLNS_ATTRIBUTE
The following examples show how to use
javax.xml.XMLConstants#XMLNS_ATTRIBUTE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLDOMWriterImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * creates a namespace attribute and will associate it with the current element in * the DOM tree. * @param prefix {@inheritDoc} * @param namespaceURI {@inheritDoc} * @throws javax.xml.stream.XMLStreamException {@inheritDoc} */ public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { if (prefix == null) { throw new XMLStreamException("prefix cannot be null"); } if (namespaceURI == null) { throw new XMLStreamException("NamespaceURI cannot be null"); } String qname = null; if (prefix.equals("")) { qname = XMLConstants.XMLNS_ATTRIBUTE; } else { qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix); } ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI); }
Example 2
Source File: AbstractDocumentComponent.java From netbeans with Apache License 2.0 | 6 votes |
/** * @return mapping from prefix to namespace. */ public Map<String, String> getPrefixes() { Map<String,String> prefixes = new HashMap<String,String>(); NamedNodeMap nodes = getPeer().getAttributes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); String name = n.getLocalName(); String prefix = n.getPrefix(); final String xmlns = XMLConstants.XMLNS_ATTRIBUTE; //NOI18N if (xmlns.equals(name) || // default namespace xmlns.equals(prefix)) { // namespace prefix String ns = n.getNodeValue(); prefixes.put(name, ns); } } String defaultNamespace = prefixes.remove(XMLConstants.XMLNS_ATTRIBUTE); if (defaultNamespace != null) { prefixes.put(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace); } return prefixes; }
Example 3
Source File: ModuleNamespaceContext.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Override public String getNamespaceURI(final String prefix) { checkArgument(prefix != null); switch (prefix) { case XMLConstants.DEFAULT_NS_PREFIX: return YangConstants.RFC6020_YIN_NAMESPACE_STRING; case XMLConstants.XML_NS_PREFIX: return XMLConstants.XML_NS_URI; case XMLConstants.XMLNS_ATTRIBUTE: return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; default: final ModuleEffectiveStatement module = prefixToModule.get(prefix); return module != null ? module.localQNameModule().getNamespace().toString() : XMLConstants.NULL_NS_URI; } }
Example 4
Source File: XMLDOMWriterImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * creates a namespace attribute and will associate it with the current element in * the DOM tree. * @param prefix {@inheritDoc} * @param namespaceURI {@inheritDoc} * @throws javax.xml.stream.XMLStreamException {@inheritDoc} */ public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { if (prefix == null) { throw new XMLStreamException("prefix cannot be null"); } if (namespaceURI == null) { throw new XMLStreamException("NamespaceURI cannot be null"); } String qname = null; if (prefix.equals("")) { qname = XMLConstants.XMLNS_ATTRIBUTE; } else { qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix); } ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI); }
Example 5
Source File: UnmarshallingContext.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public String getPrefix(String uri) { if( uri==null ) throw new IllegalArgumentException(); if( uri.equals(XMLConstants.XML_NS_URI) ) return XMLConstants.XML_NS_PREFIX; if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) ) return XMLConstants.XMLNS_ATTRIBUTE; for( int i=nsLen-2; i>=0; i-=2 ) if(uri.equals(nsBind[i+1])) if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) ) // make sure that this prefix is still effective. return nsBind[i]; if(environmentNamespaceContext!=null) return environmentNamespaceContext.getPrefix(uri); return null; }
Example 6
Source File: UnmarshallingContext.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public String getPrefix(String uri) { if( uri==null ) throw new IllegalArgumentException(); if( uri.equals(XMLConstants.XML_NS_URI) ) return XMLConstants.XML_NS_PREFIX; if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) ) return XMLConstants.XMLNS_ATTRIBUTE; for( int i=nsLen-2; i>=0; i-=2 ) if(uri.equals(nsBind[i+1])) if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) ) // make sure that this prefix is still effective. return nsBind[i]; if(environmentNamespaceContext!=null) return environmentNamespaceContext.getPrefix(uri); return null; }
Example 7
Source File: ModuleNamespaceContext.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Override public String getPrefix(final String namespaceURI) { checkArgument(namespaceURI != null); switch (namespaceURI) { case YangConstants.RFC6020_YIN_NAMESPACE_STRING: return XMLConstants.DEFAULT_NS_PREFIX; case XMLConstants.XML_NS_URI: return XMLConstants.XML_NS_PREFIX; case XMLConstants.XMLNS_ATTRIBUTE_NS_URI: return XMLConstants.XMLNS_ATTRIBUTE; default: final List<@NonNull String> prefixes = namespaceToPrefix.get(namespaceURI); return prefixes.isEmpty() ? null : prefixes.get(0); } }
Example 8
Source File: UnmarshallingContext.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public String getPrefix(String uri) { if( uri==null ) throw new IllegalArgumentException(); if( uri.equals(XMLConstants.XML_NS_URI) ) return XMLConstants.XML_NS_PREFIX; if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) ) return XMLConstants.XMLNS_ATTRIBUTE; for( int i=nsLen-2; i>=0; i-=2 ) if(uri.equals(nsBind[i+1])) if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) ) // make sure that this prefix is still effective. return nsBind[i]; if(environmentNamespaceContext!=null) return environmentNamespaceContext.getPrefix(uri); return null; }
Example 9
Source File: XMLDOMWriterImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Creates a DOM attribute and adds it to the current element in the DOM tree. * @param namespaceURI {@inheritDoc} * @throws javax.xml.stream.XMLStreamException {@inheritDoc} */ public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { if(currentNode.getNodeType() == Node.ELEMENT_NODE){ String qname = XMLConstants.XMLNS_ATTRIBUTE; ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI); }else{ //Convert node type to String throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() + "and does not allow attributes to be set "); } }
Example 10
Source File: DomXPathNamespaceResolver.java From camunda-spin with Apache License 2.0 | 5 votes |
public String getPrefix(String namespaceURI) { ensureNotNull("Namespace URI", namespaceURI); if(namespaceURI.equals(XMLConstants.XML_NS_URI)) { return XMLConstants.XML_NS_PREFIX; } if(namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) { return XMLConstants.XMLNS_ATTRIBUTE; } /** * TODO: This only works for the root element. Every child element with a 'xmlns'-attribute will be ignored. */ if (namespaceURI.equals(element.name())) { return XMLConstants.DEFAULT_NS_PREFIX; } String key = null; if(namespaces.containsValue(namespaceURI)) { for(Map.Entry<String, String> entry : namespaces.entrySet()) { if(namespaceURI.equals(entry.getValue())) { key = entry.getKey(); break; } } } return key; }
Example 11
Source File: XmlDocumentBuilder.java From xcurator with Apache License 2.0 | 5 votes |
public void addNsContextToEntityElement(Element entity, NsContext nsCtx) { for (Map.Entry<String, String> ns : nsCtx.getNamespaces().entrySet()) { String attributeName = XMLConstants.XMLNS_ATTRIBUTE; if (!ns.getKey().equals("")) { attributeName += ":" + ns.getKey(); } entity.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attributeName, ns.getValue()); } }
Example 12
Source File: XMLDOMWriterImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Creates a DOM attribute and adds it to the current element in the DOM tree. * @param namespaceURI {@inheritDoc} * @throws javax.xml.stream.XMLStreamException {@inheritDoc} */ public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { if(currentNode.getNodeType() == Node.ELEMENT_NODE){ String qname = XMLConstants.XMLNS_ATTRIBUTE; ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI); }else{ //Convert node type to String throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() + "and does not allow attributes to be set "); } }
Example 13
Source File: NamespaceImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of NamespaceImpl */ public NamespaceImpl(String namespaceURI) { super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null); init(); }
Example 14
Source File: NamespaceImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of NamespaceImpl */ public NamespaceImpl(String namespaceURI) { super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null); init(); }
Example 15
Source File: TransformedEvent.java From sis with Apache License 2.0 | 4 votes |
/** Wraps the given event with a different prefix and URI. */ NS(final Attribute event, final String prefix, final String namespaceURI) { super(event, new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, XMLConstants.XMLNS_ATTRIBUTE)); this.namespaceURI = namespaceURI; }
Example 16
Source File: NamespaceImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of NamespaceImpl */ public NamespaceImpl(String namespaceURI) { super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null); init(); }
Example 17
Source File: NamespaceImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of NamespaceImpl */ public NamespaceImpl(String namespaceURI) { super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null); init(); }
Example 18
Source File: NamespaceImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public NamespaceImpl(String prefix, String namespaceURI){ super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,prefix,namespaceURI,null); init(); }
Example 19
Source File: NamespaceImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of NamespaceImpl */ public NamespaceImpl(String namespaceURI) { super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null); init(); }
Example 20
Source File: NamespaceImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of NamespaceImpl */ public NamespaceImpl(String namespaceURI) { super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null); init(); }