Skip to content

NamespacePrefixesMap

do- edited this page May 14, 2022 · 9 revisions

NamespacePrefixesMap is a Map descendant representing aliases of namespace declarations when writing XML text.

Unlike NamespacesMap it maps namespace URIs to generated prefixes: ns0, ns1 etc. which makes sense solely for XML serialization tasks. Naturally, this is an XMLMarshaller internal class.

Constructor

const NamespacePrefixesMap = require ('node-xml-toolkit/lib/NamespacePrefixesMap.js')
let ns = new NamespacePrefixesMap (myXMLSchemata)

Generates prefixes for all namespaces in a given XMLSchemata.

Methods

QName

let qName = ns.QName (localName, namespaceURI)
  // 'DATA', null -> 'DATA'
  // 'date', 'http://www.w3.org/2001/XMLSchema' -> 'ns123:date'

Given a localName and namespaceURI, returns the qualified name good for appending to XML text.

For null namespaceURI, returns the localName.

For namespaceURI absent from the original XMLSchemata, throws an assertion error.

toString

let xml = '<' + qName + ns + '>'
  // <ns0:myTag xmlns:ns0="..." xmlns:ns1="..." ...>

Returns the string of pseudo attributes representing the actual map and good for interpolating in an opening XML tag.

Each item is prefixed with a space, including the first one.

Clone this wiki locally