-
Notifications
You must be signed in to change notification settings - Fork 5
XMLSchemata
XMLSchemata is a class representing a complete XML Schema.
It'a Map of target namespace URIs to corresponding XMLSchema objects, with some additional fields and methods.
Currently, its main purpose is to provide the stringify method.
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 = await XMLSchemata.fromFile ('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 the schema by the root element name (if possible) and using it.
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).