Class XMLDocumentGenerator
java.lang.Object
org.eclipse.lemminx.extensions.contentmodel.generator.XMLDocumentGenerator
Generates a complete XML document from a grammar (XSD, DTD, RelaxNG, RNC).
This generator creates a well-formed XML document that includes:
- XML declaration (
<?xml version="1.0" encoding="UTF-8"?>) - Grammar binding depending on the grammar type:
- XSD:
xsi:schemaLocationorxsi:noNamespaceSchemaLocation - DTD:
<!DOCTYPE root SYSTEM "uri"> - RelaxNG/RNC:
<?xml-model href="uri"?>
- XSD:
- XML body with required elements and attributes generated via
XMLElementGenerator
Example usage:
XMLDocumentGenerator generator = new XMLDocumentGenerator(sharedSettings); String xml = generator.generate(cmDocument, grammarURI, "rootElement");
-
Constructor Summary
ConstructorsConstructorDescriptionXMLDocumentGenerator(SharedSettings sharedSettings) Creates a new XML document generator with default generation settings.XMLDocumentGenerator(SharedSettings sharedSettings, XMLGenerationSettings generationSettings) Creates a new XML document generator with the given generation settings. -
Method Summary
Modifier and TypeMethodDescriptiongenerate(CMDocument cmDocument, String grammarURI) Generates a complete XML document using the first root element declared in the grammar.generate(CMDocument cmDocument, String grammarURI, String rootElementName) Generates a complete XML document from the given grammar with the specified root element name.
-
Constructor Details
-
Method Details
-
generate
Generates a complete XML document using the first root element declared in the grammar.- Parameters:
cmDocument- the content model document loaded from the grammar.grammarURI- the grammar file URI (used for grammar binding).- Returns:
- the generated XML document as a string, or empty string if the grammar has no elements.
-
generate
Generates a complete XML document from the given grammar with the specified root element name.- Parameters:
cmDocument- the content model document loaded from the grammar.grammarURI- the grammar file URI (used for grammar binding).rootElementName- the local name of the root element to generate.- Returns:
- the generated XML document as a string, or empty string if the root element is not found.
-