Examples of NamespaceContext

All get*(*) methods operate in the current scope for Namespace URI and prefix resolution.

Note that a Namespace URI can be bound to multiple prefixes in the current scope. This can occur when multiple XMLConstants.XMLNS_ATTRIBUTE ("xmlns") Namespace declarations occur in the same Start-Tag and refer to the same Namespace URI. e.g.

 <element xmlns:prefix1="http://Namespace-name-URI" xmlns:prefix2="http://Namespace-name-URI"> 

This can also occur when the same Namespace URI is used in multiple XMLConstants.XMLNS_ATTRIBUTE ("xmlns") Namespace declarations in the logical parent element hierarchy. e.g.
 <parent xmlns:prefix1="http://Namespace-name-URI"> <child xmlns:prefix2="http://Namespace-name-URI"> ... </child> </parent> 

A prefix can only be bound to a single Namespace URI in the current scope.

@author JAXP Java Community Process @author JAXP Reference Implementation @version 1.0.proposed @see javax.xml.XMLConstants declarations of common XML values @see Namespaces in XML @see Namespaces in XML Errata @see XML Schema Part2: Datatypes
  • net.sf.toxicity.util.NamespaceContext
    @author Stefan Podkowinski
  • org.apache.commons.jxpath.ri.axes.NamespaceContext
    EvalContext that walks the "namespace::" axis. @author Dmitri Plotnikov @version $Revision: 1.7 $ $Date: 2003/03/11 00:59:20 $
  • org.apache.ws.util.xml.NamespaceContext
    Interface for read only XML Namespace context processing. @author Ian Springer (ian DOT springer AT hp DOT com)
  • org.apache.xerces.xni.NamespaceContext
    Represents an interface to query namespace information. @author Andy Clark, IBM @version $Id: NamespaceContext.java,v 1.3 2001/12/12 22:33:47 elena Exp $
  • org.apache.xmlbeans.impl.values.NamespaceContext
  • org.custommonkey.xmlunit.NamespaceContext
    Interface used by XpathEngine in order to map prefixes to namespace URIs.

    This is modelled after javax.xml.namespace.NamespaceContext but reduced to our needs.

  • org.jaxen.NamespaceContext
    Resolves namespace prefixes to namespace URIs.

    The prefixes used within an XPath expression are independant of those used within any target document. When evaluating an XPath against a document, only the resolved namespace URIs are compared, not their prefixes.

    A NamespaceContext is responsible for translating prefixes as they appear in XPath expressions into URIs for comparison. A document's prefixes are resolved internal to the document based upon its own namespace nodes.

    @see BaseXPath @see Navigator#getElementNamespaceUri @see Navigator#getAttributeNamespaceUri @author bob mcwhirter
  • org.wso2.carbon.humantask.utils.NamespaceContext

  • Examples of javax.xml.namespace.NamespaceContext

            evt = er.nextEvent(); // branch
            assertTokenType(START_ELEMENT, evt.getEventType());
            se = evt.asStartElement();
            assertEquals("branch", se.getName().getLocalPart());
            assertEquals(1, countElements(se.getNamespaces()));
            NamespaceContext nsCtxt = se.getNamespaceContext();
            assertNotNull("StartElement.getNamespaceContext() should never return null", nsCtxt);
            assertEquals("url", nsCtxt.getNamespaceURI("a"));
            assertEquals("a", nsCtxt.getPrefix("url"));

            evt = er.nextEvent(); // leaf
            assertTokenType(START_ELEMENT, evt.getEventType());
            se = evt.asStartElement();
            assertEquals("leaf", se.getName().getLocalPart());
            assertEquals(0, countElements(se.getNamespaces()));
            nsCtxt = se.getNamespaceContext();
            assertEquals("url", nsCtxt.getNamespaceURI("a"));
            assertEquals("a", nsCtxt.getPrefix("url"));

            assertTrue(er.nextEvent().isEndElement()); // /leaf
            assertTrue(er.nextEvent().isEndElement()); // /branch
            assertTrue(er.nextEvent().isEndElement()); // /root
        }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

                        return be;
                    }
                    /* Ok, not woodstox impl, will be bit more work (plus less
                     * efficient, and may miss some info)... but can be done.
                     */
                    NamespaceContext nsCtxt = null;
                    if (r instanceof XMLStreamReader2) {
                        nsCtxt = ((XMLStreamReader2) r).getNonTransientNamespaceContext();
                    }
                    Map<QName,Attribute> attrs;
                    {
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

        }

        protected StartElement createStartElement(XMLStreamReader r, Location loc)
            throws XMLStreamException
        {
            NamespaceContext nsCtxt = null;
            /* Note: there's no way to get non-transient namespace context via
             * Stax 1.0 interface -- the context you can access from reader
             * remains stable only during current event.
             */
            if (r instanceof XMLStreamReader2) {
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

            String prefix;
            // Ok as is? In repairing mode need to ensure it's properly bound
            if (mNsRepairing) {
                String uri = name.getNamespaceURI();
                // First: let's see if a valid binding already exists:
                NamespaceContext ctxt = getNamespaceContext();
                prefix = (ctxt == null) ? null : ctxt.getPrefix(uri);
                if (prefix == null) {
                    // nope: need to (try to) bind
                    String origPrefix = name.getPrefix();
                    if (origPrefix == null || origPrefix.length() == 0) {
                        prefix = "";
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

             */
            String xsiTypeQname = root.getAttributeValue(SOAPConstants.XSI_NS, "type");
            if (xsiTypeQname != null) {
                Matcher m = QNAME_PATTERN.matcher(xsiTypeQname);
                if (m.matches()) {
                    NamespaceContext nc = root.getNamespaceContext();
                    this.xsiType = new QName(nc.getNamespaceURI(m.group(1)), m.group(2), m.group(1));
                } else {
                    this.xsiType = new QName(this.namespace, xsiTypeQname, "");
                }
            }
        }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

            if (xmlnsSchemeIndex >= 0) {
                xmlnsSchemeIndex += xmlnsSchemeString.length();
                int xmlnsSchemeEndIndex = this.findBalancedEndIndex(xpointer, xmlnsSchemeIndex, '(', ')');
                String namespaceScheme = xpointer.substring(xmlnsSchemeIndex, xmlnsSchemeEndIndex);
                final String[] namespaceSplit = namespaceScheme.split("=");
                xPath.setNamespaceContext(new NamespaceContext() {
                    @Override
                    public String getNamespaceURI(String prefix) {
                        if (prefix.equals(namespaceSplit[0])) {
                            return namespaceSplit[1];
                        }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

            XMLSecurityStreamWriter xmlSecurityStreamWriter = new XMLSecurityStreamWriter(outputProcessorChain);

            StringWriter stdStringWriter = new StringWriter();
            XMLStreamWriter stdXmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(stdStringWriter);

            NamespaceContext namespaceContext = new NamespaceContext() {
                @Override
                public String getNamespaceURI(String prefix) {
                    if ("t3".equals(prefix)) {
                        return "test3ns";
                    }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

                }
            }
           
            @Override
            public NamespaceContext getNamespaceContext() {
                return new NamespaceContext() {

                    public String getNamespaceURI(String prefix) {
                        for (Map.Entry<String, String> entry : namespaceMap.entrySet()) {
                            if (entry.getValue().equals(prefix)) {
                                return entry.getKey();
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

             */
            String xsiTypeQname = root.getAttributeValue(SOAPConstants.XSI_NS, "type");
            if (xsiTypeQname != null) {
                Matcher m = QNAME_PATTERN.matcher(xsiTypeQname);
                if (m.matches()) {
                    NamespaceContext nc = root.getNamespaceContext();
                    this.xsiType = new QName(nc.getNamespaceURI(m.group(1)), m.group(2), m.group(1));
                } else {
                    this.xsiType = new QName(this.namespace, xsiTypeQname, "");
                }
            }
        }
    View Full Code Here

    Examples of javax.xml.namespace.NamespaceContext

            //We'll use some reflection to grab the known namespaces from woodstox
            //or the xerces parser and fake extra namespace decls on the root elements.
            //slight performance penalty, but there already is a penalty if you are validating
            //anyway.
           
            NamespaceContext c = source.getNamespaceContext();
            final Map<String, String> nsMap = new TreeMap<String, String>();
            try {
                if (c instanceof W3CNamespaceContext) {                               
                    Element element = ((W3CNamespaceContext)c).getElement();
                    while (element != null) {
                        NamedNodeMap namedNodeMap = element.getAttributes();
                        for (int i = 0; i < namedNodeMap.getLength(); i++) {
                            Attr attr = (Attr)namedNodeMap.item(i);
                            if (attr.getPrefix() != null && attr.getPrefix().equals("xmlns")) {
                                nsMap.put(attr.getLocalName(), attr.getValue());
                            }
                        }
                        element = (Element)element.getParentNode();
                    }
                } else {
                    try {
                        //Woodstox version
                        c = (NamespaceContext)c.getClass().getMethod("createNonTransientNsContext",
                                                                     Location.class)
                            .invoke(c, new Object[1]);
                    } catch (Throwable t) {
                        //ignore
                    }
                    Field f = ReflectionUtil.getDeclaredField(c.getClass(), "mNamespaces");
                    ReflectionUtil.setAccessible(f);
                    String ns[] = (String[])f.get(c);
                    for (int x = 0; x < ns.length; x += 2) {
                        if (ns[x] == null) {
                            nsMap.put("", ns[x + 1]);
                        } else {
                            nsMap.put(ns[x], ns[x + 1]);
                        }
                    }
                }
            } catch (Throwable t) {
                //internal JDK/xerces version
                try {
                    Field f =  ReflectionUtil.getDeclaredField(c.getClass(), "fNamespaceContext");
                    ReflectionUtil.setAccessible(f);
                    Object c2 = f.get(c);
                    Enumeration<?> enm = (Enumeration<?>)c2.getClass().getMethod("getAllPrefixes").invoke(c2);
                    while (enm.hasMoreElements()) {
                        String s = (String)enm.nextElement();
                        if (s == null) {
                            nsMap.put("", c.getNamespaceURI(null));
                        } else {
                            nsMap.put(s, c.getNamespaceURI(s));
                        }
                    }
                } catch (Throwable t2) {
                    //ignore
                }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.