Platforms to show: All Mac Windows Linux Cross-Platform

Back to XMLDocumentMBS class.

XMLDocumentMBS.adoptNode(node as XMLNodeMBS) as XMLNodeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Changes the ownerDocument of a node, its children, as well as the attached attribute nodes if there are any.

If the node has a parent it is first removed from its parent child list. This effectively allows moving a subtree from one document to another.
Should not be needed in Xojo apps.

XMLDocumentMBS.ClearCache

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Frees the node cache for this document.

You should usually not need to use this method.

XMLDocumentMBS.Close

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Explicitly close document.

This frees memory for all nodes and the XML document now.
You should usually not need to use this method.

XMLDocumentMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The constructor to create a blank document.
Example

// create blank document
dim doc as new XMLDocumentMBS

dim testNode as XMLElementMBS = doc.createElement("test")

System.DebugLog "doc.append"
call doc.appendChild testNode

System.DebugLog "testNode.append"
call testNode.appendChild doc.createTextNode("Hello World")

// and make a string:
dim s as string = doc.toString

Break // see in debugger

See also:

XMLDocumentMBS.Constructor(data as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Convenience function to parse a document from a memoryblock.

See also:

XMLDocumentMBS.Constructor(data as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Convenience function to parse a document from a string.
Example

// parse it
dim doc as new XMLDocumentMBS("<test id=123>abc</test>")

// and make a string:
dim s as string = doc.toString

Break // see in debugger

See also:

XMLDocumentMBS.Constructor(namespaceURI as String, qualifiedName as string, DocumentType as XMLDocumentTypeMBS = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a DOMDocument object of the specified type with its document element.

namespaceURI: The namespace URI of the document element to create.
qualifiedName: The qualified name of the document element to be created.
DocumentType: The type of document to be created or nil. When doctype is not nil, its ownerDocument attribute is set to the document being created.

See also:

XMLDocumentMBS.createAttribute(Name as String) as XMLAttributeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an XMLAttributeMBS of the given name.

Note that the XMLAttributeMBS instance can then be set on an XMLElementMBS using the setAttributeNode method. <br>To create an attribute with a qualified name and namespace URI, use the createAttributeNS method.

name: The name of the attribute.

Returns a new XMLAttributeMBS object with the nodeName attribute set to name, and localName, prefix, and namespaceURI set to "". The value of the attribute is the empty string.

XMLDocumentMBS.createAttributeNS(namespaceURI as String, qualifiedName as String) as XMLAttributeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an attribute of the given qualified name and namespace URI.

namespaceURI: The namespace URI of the attribute to create.
qualifiedName: The qualified name of the attribute to instantiate.

XMLDocumentMBS.createCDATASection(Data as String) as XMLCDATASectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a XMLCDATASectionMBS node whose value is the specified string.

XMLDocumentMBS.createComment(Text as String) as XMLCommentMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a DOMComment node given the specified string.

XMLDocumentMBS.createDocumentFragment as XMLDocumentFragmentMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an empty XMLDocumentFragmentMBS object.

XMLDocumentMBS.createDocumentType(Name as String, PublicID as String = "", SystemID as String = "") as XMLDocumentTypeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a XMLDocumentTypeMBS node.

XMLDocumentMBS.createElement(Name as String) as XMLElementMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an element of the type specified.
Example

Dim doc As New XMLDocumentMBS

Dim testNode As XMLElementMBS = doc.createElement("test")
Call doc.appendChild testNode

MessageBox doc.toString

Note that the instance returned implements the XMLElementMBS interface, so attributes can be specified directly on the returned object.

In addition, if there are known attributes with default values, XMLAttributeMBS nodes representing them are automatically created and attached to the element.

To create an element with a qualified name and namespace URI, use the createElementNS method.
tagName The name of the element type to instantiate. For XML, this is case-sensitive.
A new XMLElementMBS object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to "".

XMLDocumentMBS.createElementNS(namespaceURI as String, qualifiedName as String) as XMLElementMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an element of the given qualified name and namespace URI.

namespaceURI: The namespace URI of the element to create.
qualifiedName: The qualified name of the element type to instantiate.

XMLDocumentMBS.createEntity(Name as String) as XMLEntityMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a new entity.

name: The name of the entity to instantiate.

XMLDocumentMBS.createEntityReference(Text as String) as XMLEntityReferenceMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates an XMLEntityReferenceMBS object.

In addition, if the referenced entity is known, the child list of the XMLEntityReferenceMBS node is made the same as that of the corresponding XMLEntityMBS node.If any descendant of the XMLEntityMBS node has an unbound namespace prefix, the corresponding descendant of the created XMLEntityReferenceMBS node is also unbound; (its namespaceURI is nil). The DOM Level 2 does not support any mechanism to resolve namespace prefixes.

name: The name of the entity to reference.

Returns the new XMLEntityReferenceMBS object.

XMLDocumentMBS.createNodeIterator(root as XMLNodeMBS = nil, whatToShow as Integer = &hFFFF, entityReferenceExpansion as boolean = false, filter as XMLNodeFilterMBS = nil) as XMLNodeIteratorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a NodeIterator object.

NodeIterators are used to step through a set of nodes, e.g. the set of nodes in a NodeList, the document subtree governed by a particular node, the results of a query, or any other set of nodes. The set of nodes to be iterated is determined by the implementation of the NodeIterator. DOM Level 2 specifies a single NodeIterator implementation for document-order traversal of a document subtree. Instances of these iterators are created by calling createNodeIterator().

To produce a view of the document that has entity references expanded and does not expose the entity reference node itself, use the whatToShow flags to hide the entity reference node and set expandEntityReferences to true when creating the iterator. To produce a view of the document that has entity reference nodes but no entity expansion, use the whatToShow flags to show the entity reference node and set expandEntityReferences to false.

root: The root node of the DOM tree
whatToShow: This attribute determines which node types are presented via the iterator.
filter: The filter used to screen nodes .
entityReferenceExpansion: The value of this flag determines whether the children of entity reference nodes are visible to the iterator. If false, they will be skipped over.

Some examples using this method:

XMLDocumentMBS.createNotation(Name as String) as XMLNotationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Create a Notation.

name: The name of the notation to instantiate

Returns a XMLNotationMBS that references the newly created XMLNotationMBS node.

XMLDocumentMBS.createProcessingInstruction(Target as String, Data as string) as XMLCDATASectionMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a XMLProcessingInstructionMBS node given the specified name and data strings.

target: The target part of the processing instruction.
data: The data for the node.

XMLDocumentMBS.createTextNode(Text as String) as XMLTextMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a XMLTextMBS node given the specified string.
Example

Dim doc As New XMLDocumentMBS
Dim element As XMLElementMBS = doc.createElement("test")

Call doc.appendChild element
Call element.appendChild doc.createTextNode("Hello World")

MessageBox doc.toString

XMLDocumentMBS.createTreeWalker(root as XMLNodeMBS = nil, whatToShow as Integer = &hFFFF, entityReferenceExpansion as boolean = false, filter as XMLNodeFilterMBS = nil) as XMLTreeWalkerMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a TreeWalker object.

TreeWalker objects are used to navigate a document tree or subtree using the view of the document defined by its whatToShow flags and any filters that are defined for the TreeWalker. Any function which performs navigation using a TreeWalker will automatically support any view defined by a TreeWalker.

Omitting nodes from the logical view of a subtree can result in a structure that is substantially different from the same subtree in the complete, unfiltered document. Nodes that are siblings in the TreeWalker view may be children of different, widely separated nodes in the original view. For instance, consider a Filter that skips all nodes except for XMLTextMBS nodes and the root node of a document. In the logical view that results, all text nodes will be siblings and appear as direct children of the root node, no matter how deeply nested the structure of the original document.

To produce a view of the document that has entity references expanded and does not expose the entity reference node itself, use the whatToShow flags to hide the entity reference node and set expandEntityReferences to true when creating the TreeWalker. To produce a view of the document that has entity reference nodes but no entity expansion, use the whatToShow flags to show the entity reference node and set expandEntityReferences to false

root: The root node of the DOM tree
whatToShow: This attribute determines which node types are presented via the tree-walker.
filter: The filter used to screen nodes
entityReferenceExpansion: The value of this flag determines whether the children of entity reference nodes are visible to the tree-walker. If false, they will be skipped over.

XMLDocumentMBS.ElementsByTagName(TagName as String) as XMLElementMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns an array of all the XMLElementMBS(s) with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of the XMLDocumentMBS tree.
Example

Dim xml As String = "<test id=""123""><f>1</f><f>2</f><f>3</f><f>4</f></test>"
Dim doc As New XMLDocumentMBS(xml)

Dim elements() As XMLElementMBS = doc.ElementsByTagName("f")

Break

TagName: The tag name of the elements to match on. The special value "*" matches all local names.

Returns a new array object containing all the matched XMLElementMBS(s).

XMLDocumentMBS.ElementsByTagNameNS(namespaceURI as string, localName as String) as XMLElementMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns an array of all the XMLElementMBS(s) with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of the XMLDocumentMBS tree.

namespaceURI: The namespace URI of the elements to match on. The special value "*" matches all namespaces.
localName: The local name of the elements to match on. The special value "*" matches all local names.

Returns a new array object containing all the matched XMLElementMBS(s).

XMLDocumentMBS.evaluate(expression as String, contextNode as XMLNodeMBS, type as Integer) as XMLXPathResultMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 23.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Evaluates an XPath expression string and returns a result of the specified type if possible.

expression: The XPath expression string to be parsed and evaluated.
contextNode: The context is context node for the evaluation of this XPath expression. Must be owned by the same document and must be a XMLDocumentMBS, XMLElementMBS, XMLAttributeMBS, XMLTextMBS, XMLCDATASectionMBS, DOMComment, XMLProcessingInstructionMBS, or XPathNamespace node.
type: If a specific type is specified, then the result will be returned as the corresponding type. This must be one of the codes of the XMLXPathResultMBS clas constants.

Retruns result of the evaluation of the XPath expression as XMLXPathResultMBS class.

Raises exception if the expression is not legal according to the rules of the DOMXPathEvaluator.
Raises exception if the result cannot be converted to return the specified type.

XMLDocumentMBS.getElementById(elementId as String) as XMLElementMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns the XMLElementMBS whose ID is given by elementId.
Example

Dim doc As New XMLDocumentMBS("<doc><test id=""1"">abc</test><test id=""2"">def</test></doc>")

// we mark this id attribute to be the id
Dim d1 As XMLElementMBS = doc.DocumentElement.FirstElementChild
Call d1.SetIdAttribute("id", True)

// now search for it
Dim element1 As XMLElementMBS = doc.getElementById("1")
Dim element2 As XMLElementMBS = doc.getElementById("2") // not marked!

Break

If no such element exists, returns nil.
Behavior is not defined if more than one element has this ID. The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return nil.

elementId: The unique id value for an element.

Returns the matching element.

XMLDocumentMBS.importNode(node as XMLNodeMBS) as XMLNodeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 23.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Imports a node from another document by cloning it to the current document.

You don't need to do this manually as the plugin will do it for you in methods as appendChild, replaceChild and insertBefore.

XMLDocumentMBS.IterateElementsByTagName(TagName as String) as XMLIterateElementsMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Iterates over the elements with matching tag name.
Example

Dim doc As New XMLDocumentMBS("<doc><test id=""1"">abc</test><test id=""2"">def</test></doc>")

For Each e As XMLElementMBS In doc.IterateElementsByTagName("test")
MessageBox e.toString
Next

For use with For Each Loops in Xojo.

XMLDocumentMBS.IterateElementsByTagNameNS(namespaceURI as string, localName as String) as XMLIterateElementsMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Iterates over the elements with matching tag name.

For use with For Each Loops in Xojo.

XMLDocumentMBS.LoadXml(data as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads XML from data.

Replaces current document with the new one.

See also:

Some examples using this method:

XMLDocumentMBS.LoadXml(data as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads xml from data.

Replaces current document with the new one.

See also:

XMLDocumentMBS.LoadXml(file as FolderItem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads xml file.

Replaces current document with the new one.
This may reference other files in same folder.

See also:

XMLDocumentMBS.LoadXmlMT(data as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads XML from data.

Replaces current document with the new one.

The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.

See also:

XMLDocumentMBS.LoadXmlMT(data as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads xml from data.

Replaces current document with the new one.

The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.

See also:

XMLDocumentMBS.LoadXmlMT(file as FolderItem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Loads xml file.

Replaces current document with the new one.
This may reference other files in same folder.

The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.

See also:

XMLDocumentMBS.NodeFromHandle(Handle as Integer) as XMLNodeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 23.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a node (or subclass) object based on a handle.

Raises exception if this handle doesn't belong to this document.

XMLDocumentMBS.normalizeDocument

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 22.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Normalizes the document.

This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form. The actual result depends on the features being set. See XMLConfigurationMBS for details.

Noticeably this method normalizes XMLTextMBS nodes, makes the document "namespace wellformed", according to the algorithm described below in pseudo code, by adding missing namespace declaration attributes and adding or changing namespace prefixes, updates the replacement tree of XMLEntityReferenceMBS nodes, normalizes attribute values, etc. <br>Mutation events, when supported, are generated to reflect the changes occurring on the document. Note that this is a partial implementation. Not all the required features are implemented. Currently XMLAttributeMBS and XMLTextMBS nodes are normalized. Features to remove XMLCommentMBS and XMLCDATASectionMBS work.

XMLDocumentMBS.renameNode(node as XMLNodeMBS, namespaceURI as String, qualifiedName as String) as XMLNodeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method XML MBS XML Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Rename an existing node.

When possible this simply changes the name of the given node, otherwise this creates a new node with the specified name and replaces the existing node with the new node as described below. This only applies to nodes of type ELEMENT_NODE and ATTRIBUTE_NODE.

When a new node is created, the following operations are performed: the new node is created, any registered event listener is registered on the new node, any user data attached to the old node is removed from that node, the old node is removed from its parent if it has one, the children are moved to the new node, if the renamed node is an XMLElementMBS its attributes are moved to the new node, the new node is inserted at the position the old node used to have in its parent's child nodes list if it has one, the user data that was attached to the old node is attach to the new node, the user data event NODE_RENAMED is fired.

When the node being renamed is an XMLAttributeMBS that is attached to an XMLElementMBS, the node is first removed from the XMLElementMBS attributes map. Then, once renamed, either by modifying the existing node or creating a new one as described above, it is put back.

node: The node to rename.
namespaceURI: The new namespaceURI.
qualifiedName: The new qualified name.

The items on this page are in the following plugins: MBS XML Plugin.


The biggest plugin in space...