XsdParser icon indicating copy to clipboard operation
XsdParser copied to clipboard

multiple schema from database

Open b0c1 opened this issue 4 years ago • 1 comments

I try to create own xsd processor based on xsdparsercore.

public class InputStreamXsdProcessor extends XsdParserCore {
	public InputStreamXsdProcessor(List<InputStream> inputStreams) {
		this.parse(inputStreams);
	}

	public InputStreamXsdProcessor(List<InputStream> inputStreams, ParserConfig config) {
		super.updateConfig(config);
		this.parse(inputStreams);
	}

	private void parse(List <InputStream> inputStreams) {
		inputStreams.forEach(stream -> parseInputStream(stream));
		this.resolveRefs();
	}

	private void parseInputStream(InputStream inputStream) {
		try {
			Node schemaNode = getSchemaNode(inputStream);

			if (isXsdSchema(schemaNode)) {
				ConfigEntryData xsdSchemaConfig = parseMappers.getOrDefault(XsdSchema.XSD_TAG, parseMappers.getOrDefault(XsdSchema.XS_TAG, null));

				if (xsdSchemaConfig == null) {
					throw new ParserConfigurationException("XsdSchema not correctly configured.");
				}

				xsdSchemaConfig.parserFunction.apply(new ParseData(this, schemaNode, xsdSchemaConfig.visitorFunction));
			} else {
				throw new ParsingException("The top level element of a XSD file should be the xsd:schema node.");
			}
		} catch (SAXException | IOException | ParserConfigurationException e) {
			Logger.getAnonymousLogger().log(Level.SEVERE, "Exception while parsing.", e);
			throw new RuntimeException(e);
		}
	}

	private Node getSchemaNode(InputStream inputStream) throws ParserConfigurationException, IOException, SAXException {
		Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
		doc.getDocumentElement().normalize();
		return doc.getFirstChild();
	}
}```

I have multiple problems with this.
1. The XsdParserCore design is bad. I can't extend simple the XsdParserCore, I must put it to same package...
2. I can't access the elements and it's based on files, not namespaces and xsd content.
3. In the `XsdParserCore` we can't resolve the namespace in the dependent xsd because in the `resolveOtherNamespaceRefs` not based on the xsd targetNamespace, it's based on files



b0c1 avatar Apr 08 '20 19:04 b0c1

Hello,

Thanks for the issue.

The XsdParserCore wasn't planned to be extended. Currently I don't have much free time to do it so I'll take it in consideration in the future when I'm able to.

lcduarte avatar Apr 08 '20 20:04 lcduarte