Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.6.2
-
None
-
None
-
Windows XP, Java 1.4
Description
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.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.getPrefix()))
}
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/ CollectPrefixValues.get.
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