### Integrate proto-backwards-compatibility-maven-plugin
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-maven-plugin/README.md
Example configuration for the proto-backwards-compatibility-maven-plugin to enable backwards incompatibility checks. Ensure proto.lock file is in the root folder.
```xml
com.salesforce.servicelibs
proto-backwards-compatibility
${proto-backwards-compatibility.version}
target/proto
${basedir}
--debug=true
backwards-compatibility-check
process-resources
```
--------------------------------
### XSOM Reference Interface Example
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-xsom/doc/implementation.html
Illustrates a typical reference interface within XSOM for schema components. This pattern supports forward references during XML schema parsing.
```java
public static interface Term {
/** Obtains a reference as a term. */
XSTerm getTerm();
}
```
--------------------------------
### Iterate Global Element Declarations
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-xsom/doc/userguide.html
Access schema information from an XSSchemaSet. This example iterates through all schemas in the set, then lists global element declarations within each schema, indicating if they are abstract.
```java
XSSchemaSet result = /* parse XML Schema */;
// iterate each XSSchema object. XSSchema is a per-namespace schema.
Iterator itr = result.iterateSchema();
while( itr.hasNext() ) {
XSSchema s = (XSSchema)itr.next();
System.out.println("Target namespace: "+s.getTargetNamespace());
Iterator jtr = s.iterateElementDecls();
while( jtr.hasNext() ) {
XSElementDecl e = (XSElementDecl)jtr.next();
System.out.print( e.getName() );
if( e.isAbstract() )
System.out.print(" (abstract)");
System.out.println();
}
}
```
--------------------------------
### Parse XML Schema from SAX Events
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-xsom/doc/userguide.html
Feed SAX2 events to XSOMParser for advanced use cases, such as parsing schemas embedded in other XML (e.g., WSDL) or generated on-the-fly. This example shows parsing a schema produced by an XSLT transformation.
```java
import com.sun.xml.xsom.parser.XSOMParser;
import com.sun.xml.xsom.XSSchemaSet;
XSOMParser parser = new XSOMParser();
parser.setErrorHandler(...);
parser.setEntityResolver(...);
// set up XSLT
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer(new StreamSource(new File("wsdl2xsd.xsl"));
ContentHandler xsomHandler = parser.getParserHandler();
// run the transformation and feed the result to XSOM
t.transform(
new StreamSource(new File("test.wsdl")),
new SAXResult(xsomhandler));
XSSchemaSet sset = parser.getResult();
```
--------------------------------
### schema2proto Command-Line Usage
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-lib/README.md
This snippet shows the command-line interface for the schema2proto tool. It lists all available options for generating proto files from XSD, such as specifying output directories, custom mappings, and documentation inclusion.
```bash
java Schema2Proto [OPTIONS] XSDFILE
Generate proto files from xsd file. Either --configFile or --outputDirectory must be specified.
--configFile name of configfile specifying these parameters (instead
of supplying them on the command line)
--customImportLocations root folder for additional imports
--customImports add additional imports
--customNameMappings translate message and field names
--customTypeMappings represent schema types as specific output types
--defaultProtoPackage default proto package of the output file if no xsd
target defaultProtoPackage is specified
--derivationBySubsumption enable derivation by subsumption
https://cs.au.dk/~amoeller/XML/schemas/xmlschema-inheritance.html
--failIfRemovedFields when using backwards compatibility check via proto.lock
file, fail if proto fields are removed
--forceProtoPackage force all types in this package
--ignoreOutputFields output field names to ignore
--includeFieldDocs include documentation for fields in output, defaults to
true
--includeMessageDocs include documentation of messages in output, defaults to
true
--includeSourceLocationInDoc include xsd source location relative to source xsd file
in docs, defaults to false
--includeValidationRules generate bufbuild/protoc-gen-validate validation
rules from xsd rules
--includeXsdOptions include message options describing the xsd type
hierarchy
--inheritanceToComposition define each xsd extension base level as a message field
instead of copying all inherited fields
--options add custom options to each protofile, ie
java_multiple_files:true
--outputDirectory path to output folder
--outputFilename name of output file
--protoLockFile Full path to proto.lock file
--skipEmptyTypeInheritance skip types just redefining other types with a different
name
```
--------------------------------
### Compile and Run Schema Dumper
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-xsom/examples/dumper/readme.txt
Compile the Java code and then run the Dumper class with a schema file as an argument.
```bash
javac *.java
```
```bash
java Dumper
```
--------------------------------
### Generate Proto from XSD using schema2proto-maven-plugin
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-maven-plugin/README.md
Configure the schema2proto-maven-plugin in your Maven build to generate Protocol Buffer files from XSD schemas. Requires `configFile` and `xsdFile` parameters.
```xml
no.entur
schema2proto-maven-plugin
1.1
netex_to_protobuf_config.yaml
target/${netexVersion}/NeTEx_publication.xsd
generate-resources
generate
```
--------------------------------
### Modify Proto Files using schema2proto-maven-plugin
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-maven-plugin/README.md
Configure the schema2proto-maven-plugin to modify existing Protocol Buffer files. This requires a `configFile` specifying the modifications.
```xml
no.entur
schema2proto-maven-plugin
1.0
netex_to_protobuf_config.yaml
generate-resources
modify
```
--------------------------------
### Parse XML Schema from Files
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-xsom/doc/userguide.html
Use XSOMParser to parse one or more schema files. Referenced schemas are automatically parsed. Call getResult() to obtain the XSSchemaSet.
```java
import com.sun.xml.xsom.parser.XSOMParser;
import com.sun.xml.xsom.XSSchemaSet;
XSOMParser parser = new XSOMParser();
parser.setErrorHandler(...);
parser.setEntityResolver(...);
parser.parseSchema( new File("myschema.xsd"));
parser.parseSchema( new File("XHTML.xsd"));
XSSchemaSet sset = parser.getResult();
```
--------------------------------
### Fix XML Schema Element Parsing
Source: https://github.com/entur/schema2proto/blob/main/schema2proto-xsom/doc/CHANGELOG.txt
Addresses a bug in parsing XML schema elements with substitution groups.
```xml
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.