SleelaDoc API
HTML documentation for the SLeeLa standard library (/lib)
Home › Packages › xml

Package xml

This package contains 9 source unit(s) defining 9 class(es) / struct(s). Each unit below lists its fields (the values it stores) and methods (the actions it performs), with a plain explanation of each.

SLPackage #sleela 2.5 (lib/xml/SLPackage.sleela)

SLPackage class

Defines the SLeeLa standard-library package for xml -- the Document Object Model (DOM) family. Exposes the package to the SLeeLa compiler, Loader, and Nordshrift.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
packageNameString packageNameNo description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
configurevoid configure(String name)No description in source.
nameString name()No description in source.
availableboolean available()No description in source.

SLXmlAspect #sleela 2.5 (lib/xml/SLXmlAspect.sleela)

SLXmlAspect class

Defines SLXmlAspect -- the conformance-aspect and quality register for the xml DOM family. It catalogues the measurable "aspects" an XML processor can satisfy (well-formedness, validity, namespace-awareness, DOM conformance, round-trip fidelity) and rates the quality with which this library addresses each, so a caller can reason about the library's standing.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
WELL_FORMEDstatic final int WELL_FORMED = 0---- the catalogued aspects ----
DOMstatic final int DOM = 1No description in source.
NAMESPACESstatic final int NAMESPACES = 2No description in source.
SERIALIZATIONstatic final int SERIALIZATION = 3No description in source.
VALIDITYstatic final int VALIDITY = 4No description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
countint count()No description in source.
nameOfString nameOf(int aspect)The human name of an aspect id.
itemOfString itemOf(int aspect)The governing standards item for an aspect (a real, citable instrument).
qualityOfint qualityOf(int aspect)Honest quality score (0..10) for how fully THIS library addresses an aspect. well-formedness, DOM, namespaces, and serialization are implemented and exercised by the demo; DTD/schema validity is not yet implemented, so it reports a low, honest score rather than a fabricated one.
bandOfString bandOf(int score)A one-word quality band for a score.
isAddressedboolean isAddressed(int aspect)True when this library implements the aspect to at least a usable degree.
overallQualityX10int overallQualityX10()The mean quality across all catalogued aspects, scaled x10 to stay integer (e.g. 68 means an average quality of 6.8 / 10).

SLXmlAttribute #sleela 2.5 (lib/xml/SLXmlAttribute.sleela)

SLXmlAttribute class

Defines SLXmlAttribute -- a single name/value attribute on a DOM element, with namespace-aware prefix/local parts.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
qnameString qnameThe qualified name exactly as given (e.g. "xml:lang").
valueString valueThe unescaped string value.
valueCellViewString[] valueCellViewNo description in source.
valueHasCellsboolean valueHasCells = falseNo description in source.
nsPrefixString nsPrefix = ""No description in source.
nsLocalString nsLocal = ""No description in source.
splitboolean split = falseNo description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
setvoid set(String qualifiedName, String v)Build an attribute from a qualified name and value.
setValueCellsvoid setValueCells(String[] cells)Attach a char-cell view of the value for correct escaping on output.
hasCellsboolean hasCells()No description in source.
valueCellsString[] valueCells()No description in source.
getNameString getName()No description in source.
getValueString getValue()No description in source.
setValuevoid setValue(String v)No description in source.
setQualifiedvoid setQualified(String prefixPart, String localPart, String v)Record an explicit prefix/local split (skips cell scanning).
resolveFromCellsvoid resolveFromCells(String[] cells)Decompose qname into prefix/local over a supplied char-cell view (the cells of qname, one glyph per cell). Finds the first ":" cell. Real char-level.
joinRangeString joinRange(String[] cells, int from, int to)Rejoin cells in [from,to) into a String (real; mirrors substringCells).
prefixString prefix()Namespace prefix ("" when unprefixed or not yet resolved).
localNameString localName()Local name ("" when not yet resolved; equals qname for a bare name).
isNamespaceDeclarationboolean isNamespaceDeclaration()True when this attribute declares a namespace (xmlns or xmlns:prefix).
sameReferenceboolean sameReference(SLXmlAttribute other)No description in source.
equalsboolean equals(SLXmlAttribute other)No description in source.
sameSubjectboolean sameSubject(SLXmlAttribute other)Alias, mirroring SLXmlNode.sameSubject (identical to equals here).
strEqboolean strEq(String a, String b)Null-safe, case-sensitive string equality (two nulls are equal).

SLXmlDocument #sleela 2.5 (lib/xml/SLXmlDocument.sleela)

SLXmlDocument class

Defines SLXmlDocument -- the DOM document. It owns the single root element, carries the XML declaration (version/encoding/standalone), acts as the factory for new nodes (createElement/createTextNode/...), and offers the document-level queries getElementById-style lookup and getElementsByTagName.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
xmlVersionString xmlVersion = "1.0"---- XML declaration + root ----
encodingString encoding = "UTF-8"No description in source.
standaloneboolean standalone = trueNo description in source.
rootSLXmlNode rootNo description in source.
writerSLXmlSerializer writerNo description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
createvoid create()Build an empty document with a default declaration and a wired serializer.
getXmlVersionString getXmlVersion()No description in source.
setXmlVersionvoid setXmlVersion(String v)No description in source.
getEncodingString getEncoding()No description in source.
setEncodingvoid setEncoding(String v)No description in source.
getStandaloneboolean getStandalone()No description in source.
setStandalonevoid setStandalone(boolean v)No description in source.
createElementSLXmlNode createElement(String tag)No description in source.
createTextNodeSLXmlNode createTextNode(String value)No description in source.
createCDataSectionSLXmlNode createCDataSection(String value)No description in source.
createCommentSLXmlNode createComment(String value)No description in source.
createProcessingInstructionSLXmlNode createProcessingInstruction(String target, String value)No description in source.
setDocumentElementSLXmlNode setDocumentElement(SLXmlNode element)Install `element` as the single document element and return it.
newRootSLXmlNode newRoot(String tag)Create, install, and return a root element named `tag`.
documentElementSLXmlNode documentElement()No description in source.
hasRootboolean hasRoot()No description in source.
getElementsByTagNameSLXmlNode getElementsByTagName(String tag)Every element in the document with tag `tag` (document order), collected into a throwaway element whose children are the matches. "*" matches all. Returns an element node acting as a NodeList; read it with childCount()/ childAt(). Returns an empty collection when there is no root.
getElementByIdSLXmlNode getElementById(String id)The first element whose "id" attribute equals `id`, or null (DOM-style getElementById; this DOM treats the literal attribute name "id").
findByIdSLXmlNode findById(SLXmlNode e, String id)No description in source.
elementCountint elementCount()Total number of element nodes in the document (root included).
depthint depth()Nesting depth of the document element (0 when empty).
declarationString declaration()The XML declaration line (<?xml version="1.0" encoding="UTF-8" ...?>).
toXmlString toXml()The whole document as compact well-formed XML (declaration + tree).
toPrettyXmlString toPrettyXml()The whole document, pretty-printed (declaration on its own line).
sameReferenceboolean sameReference(SLXmlDocument other)No description in source.
equalsboolean equals(SLXmlDocument other)No description in source.
sameStructureboolean sameStructure(SLXmlDocument other)Alias reading as "the same structure".

SLXmlNode #sleela 2.5 (lib/xml/SLXmlNode.sleela)

SLXmlNode class

Defines SLXmlNode -- the central DOM node. An element node owns an ordered list of child nodes and a list of attributes; text/CDATA/comment/PI nodes carry character data. This is the mutable tree a document, parser, and serializer all operate on.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
kindint kind---- node identity ---- nodeType: one of the SLXmlNodeType codes (1 element, 3 text, ...).
nodeNameString nodeNameFor an element: the tag name. For leaves: a conventional "#text" etc.
dataString dataCharacter data for text/CDATA/comment/PI leaves (unescaped). "" otherwise.
dataCellViewString[] dataCellViewNo description in source.
dataHasCellsboolean dataHasCells = falseNo description in source.
childrenSLXmlNode[] children = new SLXmlNode[0]No description in source.
childNint childN = 0No description in source.
attrsSLXmlAttribute[] attrs = new SLXmlAttribute[0]No description in source.
attrNint attrN = 0No description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
ensureStoresvoid ensureStores()Ensure the backing stores exist (defensive; the field initializers already allocate them, so this is a no-op for a normally `new`-ed node).
asElementvoid asElement(String tag)Make this an element node named `tag`.
asTextvoid asText(String value)Make this a text node holding `value`.
asCDatavoid asCData(String value)Make this a CDATA section holding `value`.
asProcessingInstructionvoid asProcessingInstruction(String target, String value)Make this a processing instruction with target `target` and data `value`.
asCommentvoid asComment(String value)Make this a comment holding `value`.
setDataCellsvoid setDataCells(String[] cells)Attach a char-cell view of this node's data so the serializer can escape it.
hasDataCellsboolean hasDataCells()No description in source.
dataCellsString[] dataCells()No description in source.
nodeTypeint nodeType()---- identity accessors ----
nameString name()No description in source.
nodeValueString nodeValue()No description in source.
setNodeValuevoid setNodeValue(String v)No description in source.
isElementboolean isElement()No description in source.
isTextboolean isText()No description in source.
isCharacterDataboolean isCharacterData()No description in source.
appendChildSLXmlNode appendChild(SLXmlNode child)Append a child node and return it (DOM appendChild returns the child). Reuses a freed slot when capacity exceeds the live count; else grows.
childCountint childCount()No description in source.
childAtSLXmlNode childAt(int index)The child at `index`, or null when out of range.
firstChildSLXmlNode firstChild()No description in source.
lastChildSLXmlNode lastChild()No description in source.
removeChildSLXmlNode removeChild(int index)Remove the child at `index`, preserving the order of the rest. Returns the removed node, or null when the index is invalid.
addElementSLXmlNode addElement(String tag)Convenience: create, append, and return a child element.
addTextSLXmlNode addText(String value)Convenience: append a text node with `value` (emitted verbatim).
addTextCellsSLXmlNode addTextCells(String value, String[] cells)Convenience: append a text node whose `cells` are the glyphs of its value, so the serializer escapes & < > correctly. `value` is the rejoined text.
addCommentSLXmlNode addComment(String value)Convenience: append a comment node.
attributeCountint attributeCount()No description in source.
attributeIndexint attributeIndex(String qn)Index of the attribute whose qualified name equals `qn`, or -1.
hasAttributeboolean hasAttribute(String qn)No description in source.
getAttributeString getAttribute(String qn)The value of attribute `qn`, or null when it is absent.
setAttributevoid setAttribute(String qn, String value)Set attribute `qn` to `value`, replacing an existing one or appending a new.
setAttributeCellsvoid setAttributeCells(String qn, String value, String[] cells)Set attribute `qn` to a value whose `cells` are its glyphs, so the serializer escapes & < > " correctly. `value` is the rejoined text.
attributeAtSLXmlAttribute attributeAt(int index)The attribute object at `index`, or null when out of range.
removeAttributeboolean removeAttribute(String qn)Remove attribute `qn`; return true when one was removed.
textContentString textContent()The concatenated character data of this node and all its descendants, i.e. DOM textContent. Element structure contributes no characters.
firstElementByTagSLXmlNode firstElementByTag(String tag)The first direct child element with tag name `tag`, or null.
collectByTagvoid collectByTag(String tag, SLXmlNode result)DOM getElementsByTagName: append every descendant element whose tag is `tag` (document order) into the caller-provided result node, which is used purely as an ordered collection via appendChild. "*" matches every element.
descendantElementCountint descendantElementCount()Count descendant elements (not counting this node).
depthint depth()Depth of the deepest element subtree rooted here (a leaf element is 1).
subjectIdString subjectId()The "id" attribute of this node ("" when absent or not an element). Used as part of the subject identity of an element.
sameReferenceboolean sameReference(SLXmlNode other)No description in source.
sameSubjectboolean sameSubject(SLXmlNode other)No description in source.
equalsboolean equals(SLXmlNode other)No description in source.
sameStructureboolean sameStructure(SLXmlNode other)Convenience alias reading as "the same structure".
attributesEqualboolean attributesEqual(SLXmlNode other)No description in source.
tieStrengthint tieStrength(SLXmlNode other)No description in source.
tieNameString tieName(int strength)A human word for a tie strength.
strEqboolean strEq(String a, String b)No description in source.

SLXmlNodeType #sleela 2.5 (lib/xml/SLXmlNodeType.sleela)

SLXmlNodeType class

Defines SLXmlNodeType -- the DOM node-kind registry for the xml family. Mirrors the W3C DOM nodeType constants so a node always reports an honest, catalogued kind.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
ELEMENTstatic final int ELEMENT = 1---- the DOM nodeType constants this DOM models ----
TEXTstatic final int TEXT = 3No description in source.
CDATAstatic final int CDATA = 4No description in source.
PIstatic final int PI = 7No description in source.
COMMENTstatic final int COMMENT = 8No description in source.
DOCUMENTstatic final int DOCUMENT = 9No description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
nameOfString nameOf(int kind)Human-readable kind name for a nodeType code.
isKnownboolean isKnown(int kind)True for a code this DOM recognizes.
isContainerboolean isContainer(int kind)An element is the only kind that may itself carry attributes and children.
isCharacterDataboolean isCharacterData(int kind)Text and CDATA are character-data leaves.
isLeafboolean isLeaf(int kind)A leaf node never owns element children in this DOM.

SLXmlParser #sleela 2.5 (lib/xml/SLXmlParser.sleela)

SLXmlParser class

Defines SLXmlParser -- a char-cell text-to-DOM reader for the common XML subset (elements, attributes with double-quoted values, text, comments, and self-closing tags), plus an honest structural well-formedness check. It builds an SLXmlDocument from a char-cell view of the source.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Fields — the named values this unit stores.

FieldDeclarationWhat it holds
MAX_DEPTHstatic final int MAX_DEPTH = 256No description in source.
openStackSLXmlNode[] openStackNo description in source.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
cellAtString cellAt(String[] cells, int i)No description in source.
isSpaceCellboolean isSpaceCell(String ch)No description in source.
joinRangeString joinRange(String[] cells, int from, int to)Rejoin cells in [from, to) into a String.
indexFromint indexFrom(String[] cells, int from, String needle)First index >= from whose cell equals needle, or -1.
unescapeCellsString unescapeCells(String[] cells, int from, int to)Unescape the five predefined XML entities in a rejoined text run. Operates cell-wise so "&amp;" / "&lt;" / "&gt;" / "&quot;" / "&apos;" become & < > " '.
entityString entity(String name)The replacement for a predefined entity name, or "&name;" left intact.
isWellFormedCellsboolean isWellFormedCells(String[] cells)No description in source.
seekCloseint seekClose(String[] cells, int from)Index just past the next ">" at/after the "<" at `from` (used to skip a declaration or comment coarsely); returns n when unterminated.
tagNameFromString tagNameFrom(String[] cells, int from, int to)The tag name within cells [from, to): the run up to the first whitespace.
parseCellsSLXmlDocument parseCells(String[] cells)No description in source.
firstNonSpaceint firstNonSpace(String[] cells, int from, int to)First non-whitespace cell index in [from, to), or -1 if all whitespace.
lastNonSpaceint lastNonSpace(String[] cells, int from, int to)Last non-whitespace cell index in [from, to), or -1 if all whitespace.
readAttributesvoid readAttributes(SLXmlNode el, String[] cells, int from, int to)No description in source.

SLXmlSerializer #sleela 2.5 (lib/xml/SLXmlSerializer.sleela)

SLXmlSerializer class

Defines SLXmlSerializer -- renders a DOM tree (SLXmlNode) back to well-formed XML text, with correct character escaping and optional pretty indentation.

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
textCellString textCell(String ch)Map one glyph cell to its XML character-data replacement (& < > escaped).
attrCellString attrCell(String ch)Map one glyph cell for an attribute value (adds the double-quote entity).
escapeTextCellsString escapeTextCells(String[] cells)Escape element character data given its char-cell view (real).
escapeAttributeCellsString escapeAttributeCells(String[] cells)Escape an attribute value given its char-cell view (real).
indentString indent(int n)n levels of two-space indentation.
attrValueString attrValue(SLXmlAttribute a)The escaped form of an attribute's value: its char-cell view when supplied (correctly escaped), else the raw value verbatim (known-safe content).
textValueString textValue(SLXmlNode node)The escaped form of a text/CDATA node's data: its char-cell view when supplied (correctly escaped), else the raw data verbatim.
openTagString openTag(SLXmlNode e)The opening tag (with attributes) for an element node.
renderNodeString renderNode(SLXmlNode node, int level, boolean pretty)Serialize `node` and its subtree at indent level `level`, pretty or compact.
toXmlString toXml(SLXmlNode root)Compact one-line serialization of a subtree.
toPrettyXmlString toPrettyXml(SLXmlNode root)Pretty, indented, multi-line serialization of a subtree.

xml-dom #sleela 2.5 (lib/xml/xml-dom.sleela)

XmlDom class

Carries the standard Metadata Class record — eleven catalogued provenance attributes (version, id, author, date, copyright, trademark, corporation, origin, birth date, science rating, national schedule) with matching get/set accessors. These are omitted from the tables below for brevity.

Methods — the actions this unit can perform.

MethodSignatureWhat it does
buildCatalogSLXmlDocument buildCatalog()No description in source.
nameCellsString[] nameCells()The glyph cells of "Jack & Jill <xml>" (one per index). The opaque built-in String cannot be sliced in-language, so escapable content is spelled out as cells, exactly as lib/text/SLString prescribes.
roundTripCellsString[] roundTripCells()The glyph cells of a tiny document "<doc><p id=\"x1\">hi</p></doc>" used to demonstrate the text-to-DOM round trip over the char-cell parser.
mainvoid main()No description in source.
demoEqualityvoid demoEquality()Demonstrate and verify the three-rung equality ladder on small, standalone trees, plus the reflexive / symmetric / idempotent charge guarantees.
makeItemSLXmlNode makeItem(String id, String text)Build a standalone <item id=.. ><name>text</name></item> subtree for the equality demonstration. Children are bound to typed locals before use.
nameTextString nameText(SLXmlNode item)The text of an item's <name> child ("" when absent).
qualityTextString qualityText(SLXmlNode item)The text of an item's <quality> child ("" when absent).