You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "patins (JIRA)" <xe...@xml.apache.org> on 2005/06/24 21:25:58 UTC

[jira] Created: (XERCESJ-1086) possibility to access namespace-to-prefix bindings from original schema

possibility to access namespace-to-prefix bindings from original schema
-----------------------------------------------------------------------

         Key: XERCESJ-1086
         URL: http://issues.apache.org/jira/browse/XERCESJ-1086
     Project: Xerces2-J
        Type: Improvement
  Components: XML Schema API  
    Versions: 2.6.2    
 Environment: Windows XP,  Java 1.4
    Reporter: patins
    Priority: Minor


Hello, I have build a XML editor and my functionality  "create new document from given schema"
needs a way to get prefixes for namespaces used in the XML Schema so they
can be used in the instance conforming to that schema (in contrast to the need to
"randomly" image prefixes). E.g.  XHTML including MathML like

        <h1>
            <math:math>
                <math:arccos/>
            </math:math>
        </h1>

uses the "math" prefix automatically for elements added from the MathML schema 
(an example of XHTML using MathML is included in my XDoc program at 
http://xdoc.sourceforge.net/) since this prefix was already used in the schema which
includes mathml into xhtml).
Currently I use following solution in my editor with modified Xerces source files:

in XSDHandler.java:
 sg.addDocument(currSchemaInfo.fSchemaDoc, (String)fDoc2SystemId.get(currSchemaInfo));

in the original, currSchemaInfo.fSchemaDoc was "nulled":
 sg.addDocument(null, (String)fDoc2SystemId.get(currSchemaInfo.fSchemaDoc));
with following comment: 
// REVISIT: don't expose the DOM tree
Anyone knows why?

Now I modify "addDocument" to collect the prefixes from the DOM tree:
in SchemaGrammar.java:

public synchronized void addDocument(Object document, String location) {
        if (fDocuments == null) {
            fDocuments = new Vector();
            fLocations = new Vector();
        }
        fDocuments.addElement(document);
        fLocations.addElement(location);
        /*the rest of the method is new:*/
        Document doc=((Document)document);
        NamedNodeMap attrs=doc.getDocumentElement().getAttributes();
        for (int i=0; i<attrs.getLength(); i++)
        if ("xmlns".equals(attrs.item(i).getPrefix())) {
          Attr attr=(Attr)attrs.item(i);
          CollectPrefixNames.add(attr.getLocalName());
          CollectPrefixValues.add(attr.getValue());
        }
    }

with following public attributes:

    public Vector CollectPrefixNames=new Vector();
    public Vector CollectPrefixValues=new Vector();

So i know the ith prefix/namespace pair with CollectPrefixNames.get(i)/ CollectPrefixValues.get(i).
By the way its not important to "collect" the DOM instance, I only need to get the prefixes.

If now someone says: "Then please open that XML Schema and collect the prefixes on your
own" I say that this would mean building the DOM tree 
*first for reading in the schema in the validation process and
*second for just collecting the namespace prefixes.
So it takes nearly twice computation time.
Since this is the only lack of functionality I found in Xerces (besides some bugs)
in combination with my XML editor "XDoc" which is very tight bound to Xerces, 
it would be nice if
the changes of above could be added by someone







-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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