Reputation: 1191
I want to get a XSD file containing a redefine element with another schemaLocation to a String, where the redefine is already handled (The string should represent the merged 2 XSD files). Is this even possible?
(I am using Xerces2-j --> java)
I am not able to generate an Document or valid string from a Schema:
SchemaFactory schemaFactory =
SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1");
Schema schemaXSD = schemaFactory.newSchema( new File ( "example.xsd" ) );
Or let the XML parser handle the redefine (This loads the redefine as a node without opening/loading the second file):
DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
DocumentBuilder parser = parserFactory.newDocumentBuilder();
return parser.parse(new File ( "example.xsd" ));
Upvotes: 2
Views: 1349
Reputation: 21658
Let's see first if I can illustrate your question, based on what I understand it to be.
Say you have schema A.xsd:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Base">
<xsd:sequence>
<xsd:element name="First"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
And a redefining one (B redefines A):
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XSR Module (http://www.paschidev.com)-->
<xsd:schema xmlns="[{no target namespace}]" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="[{no target namespace}]" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:redefine schemaLocation="A.xsd">
<xsd:complexType name="Base">
<xsd:complexContent>
<xsd:extension base="Base">
<xsd:sequence>
<xsd:element name="Second" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:redefine>
</xsd:schema>
My understanding of your saying a String, where the redefine is already handled (The string should represent the merged 2 XSD files)
would be this one below:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xmlns="">Generated from "Set1" under "Release1"</xsd:documentation>
</xsd:annotation>
<xsd:complexType name="Base">
<xsd:sequence>
<xsd:element name="First" type="xsd:anyType"/>
<xsd:element minOccurs="0" name="Second" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
If that's what you're asking, then I am not aware of any Java solution which would automatically do the requested refactoring. It is possible to do it; from what I know, you have to write the code yourself.
The only tool I am aware of, specifically designed to also cover your scenario, is the one I am associated with, but that runs on .NET only (recently it requires .NET 4.0 which puts Mono platforms out of reach).
Upvotes: 1