You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by de...@compchemcons.com on 2005/08/30 16:39:00 UTC
namespace prefix problem
Hi,
I am reading a XML-Schema which itselfs imports other schemas.
The schema looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema targetNamespace="http://www.cdisc.org/ns/odm/v1.2"
xmlns="http://www.cdisc.org/ns/odm/v1.2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:sas="http://www.sas.com/xml/schemas"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<!--
import ODM foundation schemas
-->
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
<!-- include here any vendor extensions -->
<xs:include schemaLocation="sas-extension.xsd"/>
</xs:schema>
Now, for a reason nothing to do with XMLBeans, I need the prefixes that were used in the schema for each of the namespaces. I realize the prefixes are nothing fixed, one could use others, but I would like to know them anyway.
>From the mailing list, I found some information that getting the prefixes was not possible in XMLBeans 1.X, and I wander whether it is possible to retrieve them in 2.0.
With my current code, I do not see them when e.g. using
SchemaProperty[] attributes = sge[i].getType().getAttributeProperties();
So my question is: is it possible to retrieve the used prefixes with XMLBeans 2.0 ?
Part of my current code is below.
With best regards
Jozef
=============
List sdocs = new ArrayList();
XmlOptions xmloptions = new XmlOptions();
xmloptions.setLoadLineNumbers().setLoadMessageDigest();
xmloptions.setCompileDownloadUrls(); // allow compilation of schemas that are imported/included using a URL
// xmloptions.setSaveNamespacesFirst(); // just trying, 30.8.2005
try {
sdocs.add(XmlObject.Factory.parse(schemaFile, xmloptions));
} catch (Exception e) {
System.err.println( schemaFile + " not loadable: " + e );
String errormessage = "Could not read the Schema File:\n" + schemaFile.getAbsolutePath();
JOptionPane.showMessageDialog(new MyJFrame(),errormessage);
OK = false;
}
if(OK == true) {
XmlObject[] schemas = (XmlObject[])sdocs.toArray(new XmlObject[0]);
XmlObject mySchema = schemas[0];
System.out.println("Schema validation gives : " + mySchema.validate());
// compile the schemas
SchemaTypeLoader sLoader = null;
Collection compErrors = new ArrayList();
XmlOptions schemaOptions = new XmlOptions();
schemaOptions.setCompileDownloadUrls(); // allow import of other schemas using URLs
schemaOptions.setErrorListener(compErrors);
try {
if (schemas != null && schemas.length > 0) sts = XmlBeans.compileXsd(schemas, sLoader, schemaOptions);
} catch (Exception e) {
if (compErrors.isEmpty() || !(e instanceof XmlException)) {
e.printStackTrace(System.err);
}
System.out.println("Schema invalid:" + (partial ? " couldn't recover from errors" : ""));
for (Iterator i = compErrors.iterator(); i.hasNext(); ) System.out.println(i.next());
String errormessage = "Invalid ODM Schema \n" + "could not convert Schema to ODM elements";
JOptionPane.showMessageDialog(new MyJFrame(), errormessage);
OK = false;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org