-
Notifications
You must be signed in to change notification settings - Fork 4
XMLSchemata
XMLSchemata is a class representing a complete set of XMLSchema instances, with all imports resolved.
More precisely, it's a Map of target namespace URIs to corresponding XMLSchema objects, with some additional fields and methods.
The sole purpose of this class is to produce XMLMarshaller instances for translating data objects into valid XML documents according to a given XML Schema.
const xs = new XMLSchemata ('wsdl_related_stuff.xsd')
const m = xs.createMarshaller (
localName
, namespaceURI
, {space: 2} // see XMLPrinter for more
)
const xml = m.stringify (data)Validating existing XML content is not supported, as of yet.
const xs = new XMLSchemata ('wsdl_related_stuff.xsd') // or some.wsdlThis loads XML schemata starting with the provided file and then hierarchically by import elements.
-
importis supported, butincludeis not yet; - only relative paths are supported as
schemaLocations.
This method creates an instance of XMLMarshaller corresponding to the complex type with the mentioned localName and namespaceURI. That object is ready to serialize data to XML according to that schema fragment.
This method does exactly the opposite to XMLNode.toObject but somewhat analogous to JSON.stringify: it serializes a plain object to XML according to the schema[ta] loaded.
The input object must consist of exactly one entry with the key corresponding to the local name of some complex type:
const xs = new XMLSchemata ('wsdl_related_stuff.xsd')
const xml = xs.stringify ({
MySoapRequest: {
id: 1,
amount: 1000,
//...
}
})Actually, the serialization is done by XMLMarshaller -- see the corresponding page for details, e. g. on current limitations.
XMLSchemata's stringify method is only a convenience wrapper method creating a temporary XMLMarshaller guessing (if possible) the schema by the root element name and using it.
Wraps a pair of arguments in a special object to fill in xs:any wildcards during stringify.
xml and attr may be passed as two separate arguments or as a 2-element Array.
const xml = '<someRequest>CODE</someRequest>'
const attr = {Id: 1}
const Envelope = {Body: XMLSchemata.any (xml, attr)}
// = {null: {"<someRequest>CODE</someRequest>": {Id: 1}}}
const Envelope = {Body: XMLSchemata.any ([xml, attr])}
// same resultA raw String to be injected by stringify as any's content without any additional processing (e. g. escaping unsafe characters).
An object to be injected as anyAttribute's attribute-like key/value pairs: real attributes, or maybe namespace definitions. Values are not processed, neither are keys, so the latter may contain raw namespace prefixes.
This parameter is optional.
The [Symbol ('_index')] field contains the map of all named schema objects to Sets of corresponding target namespaces. Normally, each of such sets must contain only one element. In this case, it's possible to unambiguously detect the schema by only a local element name (like MyVerySpecialRequestType).