xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wesley Leggette (JIRA)" <xmlbeans-...@xml.apache.org>
Subject [jira] Created: (XMLBEANS-418) Ability to obtain QName for xsi:type field, if set
Date Thu, 15 Oct 2009 02:01:31 GMT
Ability to obtain QName for xsi:type field, if set

                 Key: XMLBEANS-418
                 URL: https://issues.apache.org/jira/browse/XMLBEANS-418
             Project: XMLBeans
          Issue Type: New Feature
          Components: XmlObject
    Affects Versions: TBD
            Reporter: Wesley Leggette
             Fix For: TBD

In my schema, I am allowing extensibility using the xsi:type attribute. To faciliate code
separation, I generally have schema components which define a particular inherited type (generally
by extension of a base type) for which particular instances will be inserted into the document.
These types have generic properties that I want all code to be able to understand, and only
compile the schema into the more specific code which needs more information about the type.

However, for both debugging, logging, and for using in Map keys I'd like easy access to the
QName defined in the xsi:type attribute even if that type is not understood by the compiled

I have implemented the following utility method to accomplish this:


   public static QName getXsiType(final XmlObject object)
      XmlCursor cursor = object.newCursor();
      final String xsiType =
            cursor.getAttributeText(new QName("http://www.w3.org/2001/XMLSchema-instance",
      if (xsiType == null)
         return null;

      final String[] toks = xsiType.split(":");
      String prefix;
      String localName;
      if (toks.length > 1)
         prefix = toks[0];
         localName = toks[1];
         prefix = "";
         localName = toks[0];

      QName namespace = null;
      cursor = object.newCursor();
         if (cursor.isNamespace() && cursor.getName().getLocalPart().equals(prefix))
            namespace = cursor.getName();
      } while (namespace == null && !cursor.isEnd());
      // final String namespace = cursor.toNextAttribute()
      // object.getDomNode().getAttributes().getNamedItem("xmlns:" + prefix).getNodeValue();

      // TODO: Obviously we don't support this too well here, we're borked
      // if xmlns isn't defined directly on the node. We should probably
      // be okay for the near future in any case.
      if (namespace == null)
         return new QName(localName);
         return new QName(namespace.getNamespaceURI(), localName);


I would think this sort of information would be ideal to be added onto the XmlObject base

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org

View raw message