juno.xml.dom Module

Provides standards-based support for processing XML.

Licence
See licence.txt for use and distribution terms.

class XmlNamespaceManager;

Adds namespaces to a collection and provides scope management.

Examples
 scope mgr = new XmlNamespaceManager;
 mgr.addNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
 mgr.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
 mgr.addNamespace("rss", "http://purl.org/rss/1.0/");

 scope doc = new XmlDocument;
 doc.load("http://del.icio.us/rss");
 foreach (node; doc.documentElement.selectNodes("/rdf:RDF/rss:item", mgr)) {
   if (node !is null)
     writefln(node.text);
 }

void addNamespace(char[] prefix, char[] uri);

Adds the given namespace to the collection.

Parameters
char[] prefix
The prefix to associate with the namespace being added.
char[] uri
The namespace to add.

bool hasNamespace(char[] prefix);

Retrieves a value indicating whether the supplied prefix has a namespace for the current scope.

Parameters
char[] prefix
The prefix of the namespace to find.

Returns
true if a namespace is defined; otherwise, false.

char[] lookupPrefix(char[] uri);

Finds the prefix with the given namespace.

Parameters
char[] uri
The namespace to resolve for the prefix.

Returns
The matching prefix.

char[] lookupNamespace(char[] prefix);

Finds the namespace for the specified prefix.

Parameters
char[] prefix
The prefix whose namespace you want to resolve.

Returns
The namespace for prefix.

bool popScope();

Pops a namespace scope off the stack.

Returns
true if there are namespace scopes left on the stack; otherwise, false.

void pushScope();

Pushes a namespace scope onto the stack.

int opApply(int delegate(ref char[] line) action);

Provides foreach-style iteratation through the prefixes stored.

abstract class XmlNodeList;

Represents an ordered collection of nodes.

abstract XmlNode item(int index);
XmlNode opIndex(int i);

Retrieves the node at the given index.

Parameters
int index
The index into the list of nodes.

Returns
The node in the collection at index.

abstract int size();

Gets the number of nodes in the collection.

Returns
The number of nodes.

abstract int opApply(int delegate(ref XmlNode) action);

Provides foreach iteration over the collection of nodes.

abstract class XPathNavigator;

Provides a way to navigate XML data.

bool matches(char[] xpath);

Determines whether the current node matches the specified XPath expression.

XmlNodeList select(char[] xpath);

Selects a node set using the specified XPath expression.

XmlNodeList selectAncestors();

Selects all the ancestor nodes of the current node.

XmlNodeList selectDescendants();

Selects all the descendant nodes of the current node.

XmlNodeList selectChildren();

Selects all the child nodes of the current node.

class XmlNamedNodeMap;

Represents a collection of nodes that can be accessed by name or index.

XmlNode getNamedItem(char[] name);

Retrieves the node specified by name.

Parameters
char[] name
The qualified name of the node to retrieve.

Returns
The node with the specified name.

XmlNode getNamedItem(char[] localName, char[] namespaceURI);

Retrieves the node with the matching localName and namespaceURI.

Parameters
char[] localName
The local name of the node to retrieve.
char[] namespaceURI
The namespace URI of the node to retrieve.

Returns
The node with the matching local name and namespace URI.

XmlNode removeNamedItem(char[] name);

Removes the node with the specified name.

Parameters
char[] name
The qualified name of the node to remove.

Returns
The node removed.

XmlNode removeNamedItem(char[] localName, char[] namespaceURI);

Removes the node with the matching localName and namespaceURI.

Parameters
char[] localName
The local name of the node to remove.
char[] namespaceURI
The namespace URI of the node to remove.

Returns
The node removed.

XmlNode setNamedItem(XmlNode node);

Adds a node using its name property.

Parameters
XmlNode node
The node to store.

Returns
The old node.

XmlNode item(int index);

Retrieves the node at the specified index.

Parameters
int index
The position of the node to retrieve.

Returns
The node at the specified index.

int size();

Gets the number of nodes.

Returns
The number of nodes.

int opApply(int delegate(ref XmlNode) action);

Provides support for foreach iteration over the collection of nodes.

class XmlAttributeCollection: juno.xml.dom.XmlNamedNodeMap;

Represents a collection of attributes that can be accessed by name or index.

final XmlAttribute opIndex(int index);

Gets the attribute at the specified index.

Parameters
int index
The index of the attribute.

Returns
The attribute at the specified index.

final XmlAttribute opIndex(char[] name);

Gets the attribute with the specified name.

Parameters
char[] name
The qualified name of the attribute.

Returns
The attribute with the specified name.

final XmlAttribute opIndex(char[] localName, char[] namespaceURI);

Gets the attribute with the specified local name and namespace URI.

Parameters
char[] localName
The local name of the attribute.
char[] namespaceURI
The namespace URI of the attribute.

Returns
The attribute with the specified local name and namespace URI.

abstract class XmlNode;

Represents a single node in the XML document.

XmlNode clone();

Creates a duplicate of this node.

Returns
The cloned node.

XmlNode cloneNode(bool deep);

Creates a duplicate of this node.

Parameters
bool deep
true to recursively clone the subtree under this node; false to clone only the node itself.

Returns
The cloned node.

XmlNode appendChild(XmlNode newChild);

Adds the specified node to the end of the list of child nodes.

Parameters
XmlNode newChild
The node to add.

Returns
The node added.

XmlNode insertBefore(XmlNode newChild, XmlNode refChild);

Inserts the specified node immediately before the specified reference node.

Parameters
XmlNode newChild
The node to insert.
XmlNode refChild
The reference node. The newChild is placed before this node.

Returns
The inserted node.

XmlNode insertAfter(XmlNode newChild, XmlNode refChild);

Inserts the specified node immediately after the specified reference node.

Parameters
XmlNode newChild
The node to insert.
XmlNode refChild
The reference node. The newChild is placed after this node.

Returns
The inserted node.

XmlNode replaceChild(XmlNode newChild, XmlNode oldChild);

Replaces the oldChild node with the newChild node.

Parameters
XmlNode newChild
The new node to put in the child list.
XmlNode oldChild
The node being replaced in the child list.

Returns
The replaced node.

XmlNode removeChild(XmlNode oldChild);

Removes the specified child node.

Parameters
XmlNode oldChild
The node being removed.

Returns
The removed node.

void removeAll();

Removes all the child nodes.

XPathNavigator createNavigator();

Creates an XPathNavigator for navigating this instance.

XmlNode selectSingleNode(char[] xpath, XmlNamespaceManager nsmgr = cast(XmlNamespaceManager)null);

Selects the first node that matches the XPath expression.

Parameters
char[] xpath
The XPath expression.
XmlNamespaceManager nsmgr
The namespace resolver to use.

Returns
The first XmlNode that matches the XPath query.

XmlNodeList selectNodes(char[] xpath, XmlNamespaceManager nsmgr = cast(XmlNamespaceManager)null);

Selects a list of nodes matching the XPath expression.

Parameters
char[] xpath
The XPath expression.
XmlNamespaceManager nsmgr
The namespace resolver to use.

Returns
An XmlNodeList containing the nodes matching the XPath query.

abstract XmlNodeType nodeType();

Gets the type of the current node.

Returns
One of the XmlNodeType values.

char[] prefix();

Gets the namespace prefix of this node.

Returns
The namespace prefix for this node. For example, prefix is 'bk' for the element <bk:book>.

abstract char[] localName();

Gets the local name of the node.

Returns
The name of the node with the prefix removed.

abstract char[] name();

Gets the qualified name of the node.

Returns
The qualified name of the node.

char[] namespaceURI();

Gets the namespace URI of the node.

Returns
The namespace URI of the node.

void text(char[] value);
char[] text();

Gets or sets the values of the node and its child nodes.

Returns
The values of the node and its child nodes.

void xml(char[] value);
char[] xml();

Gets or sets the markup representing the child nodes.

Returns
The markup of the child nodes.

void value(char[] value);
char[] value();

Gets or sets the value of this node.

bool hasChildNodes();

Gets a value indicating whether this node has any child nodes.

Returns
true if the node has child nodes; otherwise, false.

XmlNodeList childNodes();

Gets all the child nodes of the node.

Returns
An XmlNodeList containing all the child nodes of the node.

XmlNode firstChild();

Gets the first child of the node.

Returns
The first child of the node. If there is no such node, null is returned.

XmlNode lastChild();

Gets the last child of the node.

Returns
The last child of the node. If there is no such node, null is returned.

XmlNode previousSibling();

Gets the node immediately preceding this node.

Returns
The preceding XmlNode. If there is no such node, null is returned.

XmlNode nextSibling();

Gets the node immediately following this node.

Returns
The following XmlNode. If there is no such node, null is returned.

XmlNode parentNode();

Gets the parent node of this node.

Returns
The XmlNode that is the parent of this node.

XmlDocument ownerDocument();

Gets the XmlDocument to which this node belongs.

Returns
The XmlDocument to which this node belongs.

XmlAttributeCollection attributes();

Gets an XmlAttributeCollection containing the attributes of this node.

Returns
An XmlAttributeCollection containing the attributes of this node.

final int opApply(int delegate(ref XmlNode) action);

Provides support for foreach iteration over the nodes.

class XmlAttribute: juno.xml.dom.XmlNode;

Represents an attribute.

bool specified();

Gets a value indicating whether the attribute was explicitly set.

Returns
true if the attribute was explicitly set; otherwise, false.

abstract class XmlLinkedNode: juno.xml.dom.XmlNode;

Represents a node with child nodes immediately before and after this node.

abstract class XmlCharacterData: juno.xml.dom.XmlLinkedNode;

Provides text manipulation methods.

void appendData(char[] strData);

Appends the specified string to the end of the character data.

Parameters
char[] strData
The string to append to the existing string.

void insertData(int offset, char[] strData);

Inserts the specified string at the specified offset.

Parameters
int offset
The position within the string to insert the specified string data.
char[] strData
The string data that is to be inserted into the existing string.

void replaceData(int offset, int count, char[] strData);

Replaces the specified number of characters starting at the specified offset with the specified string.

Parameters
int offset
The position within the string to start replacing.
int count
The number of characters to replace.
char[] strData
The new data that replaces the old data.

void deleteData(int offset, int count);

Removes a range of characters from the string data.

Parameters
int offset
The position within the string to start deleting.
int count
The number of characters to delete.

char[] substring(int offset, int count);

Retrieves a substring of the full string from the specified range.

Parameters
int offset
The position within the string to start retrieving.
int count
The number of characters to retrieve.

int length();

Gets the length of the data.

Returns
The length of the string data.

void data(char[] value);
char[] data();

Gets or sets the data of the node.

Returns
The data of the node.

class XmlCDataSection: juno.xml.dom.XmlCharacterData;

Represents a CDATA section.

class XmlComment: juno.xml.dom.XmlCharacterData;

Represents the content of an XML comment.

class XmlText: juno.xml.dom.XmlCharacterData;

Represents the text content of an element or attribute.

XmlText splitText(int offset);

Splits the node into two nodes at the specified offset, keeping both in the tree as siblings.

Parameters
int offset
The position at which to split the node.

Returns
The new node.

class XmlEntity: juno.xml.dom.XmlNode;

Represents an entity declaration, such as <!ENTITY...>.

final char[] publicId();

Gets the value of the identifier on the entity declaration.

Returns
The identifier on the entity.

final char[] systemId();

Gets the value of the system identifier on the entity declaration.

Returns
The system identifier on the entity.

final char[] notationName();

Gets the name of the NDATA attribute on the entity declaration.

Returns
The name of the NDATA attribute.

class XmlEntityReference: juno.xml.dom.XmlLinkedNode;

Represents an entity reference node.

class XmlNotation: juno.xml.dom.XmlNode;

Represents a notation declaration such as <!NOTATION...>.

class XmlDocumentType: juno.xml.dom.XmlLinkedNode;

Represents the document type declaration.

final XmlNamedNodeMap entities();

Gets the collection of XmlEntity nodes declared in the document type declaration.

Returns
An XmlNamedNodeMap containing the XmlEntity nodes.

final XmlNamedNodeMap notations();

Gets the collection of XmlNotation nodes present in the document type declaration.

Returns
An XmlNamedNodeMap containing the XmlNotation nodes.

class XmlDocumentFragment: juno.xml.dom.XmlNode;

Represents a lightweight object useful for tree insert operations.

class XmlElement: juno.xml.dom.XmlLinkedNode;

Represents an element.

char[] getAttribute(char[] name);

Returns the value for the attribute with the specified name.

Parameters
char[] name
The qualified name of the attribute to retrieve.

Returns
The value of the specified attribute.

char[] getAttribute(char[] localName, char[] namespaceURI);

Returns the value for the attribute with the specified local name and namespace URI.

Parameters
char[] localName
The local name of the attribute to retrieve.
char[] namespaceURI
The namespace URI of the attribute to retrieve.

Returns
The value of the specified attribute.

XmlAttribute getAttributeNode(char[] name);

Returns the attribute with the specified name.

Parameters
char[] name
The qualified name of the attribute to retrieve.

Returns
The matching XmlAttribute.

XmlAttribute getAttributeNode(char[] localName, char[] namespaceURI);

Returns the attribute with the specified local name and namespace URI.

Parameters
char[] localName
The local name of the attribute to retrieve.
char[] namespaceURI
The namespace URI of the attribute to retrieve.

Returns
The matching XmlAttribute.

bool hasAttribute(char[] name);

Determines whether the node has an attribute with the specified name.

Parameters
char[] name
The qualified name of the attribute to find.

Returns
true if the node has the specified attribute; otherwise, false.

bool hasAttribute(char[] localName, char[] namespaceURI);

Determines whether the node has an attribute with the specified local name and namespace URI.

Parameters
char[] localName
The local name of the attribute to find.
char[] namespaceURI
The namespace URI of the attribute to find.

Returns
true if the node has the specified attribute; otherwise, false.

void setAttribute(char[] name, char[] value);

Sets the value of the attribute with the specified name.

Parameters
char[] name
The qualified name of the attribute to create or alter.
char[] value
The value to set for the attribute.

XmlAttribute setAttributeNode(XmlAttribute newAttr);

Adds the specified attribute.

Parameters
XmlAttribute newAttr
The attribute to add to the attribute collection for this element.

Returns
If the attribute replaces an existing attribute with the same name, the old attribute is returned; otherwise, null is returned.

void removeAttribute(char[] name);

Removes an attribute by name.

Parameters
char[] name
The qualified name of the attribute to remove.

void removeAttribute(char[] localName, char[] namespaceURI);

Removes an attribute with the specified local name and namespace URI.

Parameters
char[] localName
The local name of the attribute to remove.
char[] namespaceURI
The namespace URI of the attribute to remove.

XmlAttribute removeAttributeNode(XmlAttribute oldAttr);

Removes the specified attribute.

Parameters
XmlAttribute oldAttr
The attribute to remove.

Returns
The removed attribute or null if oldAttr is not an attribute of the element.

XmlAttribute removeAttributeNode(char[] localName, char[] namespaceURI);

Removes the attribute specified by the local name and namespace URI.

Parameters
char[] localName
The local name of the attribute.
char[] namespaceURI
The namespace URI of the attribute.

Returns
The removed attribute.

void normalize();

Collapses all adjacent XmlText nodes in the sub-tree.

XmlNodeList getElementsByTagName(char[] name);

Returns an XmlNodeList containing the descendant elements with the specified name.

Parameters
char[] name
The qualified name tag to match.

Returns
An XmlNodeList containing a list of matching nodes.

bool hasAttributes();

Gets a value indicating whether the node has any attributes.

Returns
true if the node has attributes; otherwise, false.

class XmlProcessingInstruction: juno.xml.dom.XmlLinkedNode;

Represents a processing instruction.

class XmlDeclaration: juno.xml.dom.XmlLinkedNode;

Represents the XML declaration node.

final void encoding(char[] value);
final char[] encoding();

Gets or sets the encoding level of the XML document.

Returns
The character encoding name.

final void standalone(char[] value);
final char[] standalone();

Gets or sets the value of the standalone attribute.

Returns
Valid values are "yes" if all entity declarations are contained within the document or "no" if an external DTD is required.

final char[] xmlversion();

Gets the XML version of the document.

class XmlImplementation;

Provides methods that are independent of a particular instance of the Document Object Model.

final bool hasFeature(char[] strFeature, char[] strVersion);

Tests if the specified feature is supported.

Parameters
char[] strFeature
The package name of the feature to test.
char[] strVersion
The version number of the package name to test.

Returns
true if the feature is implemented in the specified version; otherwise, false.

class XmlDocument: juno.xml.dom.XmlNode;

Represents an XML document.

this();

Initializes a new instance.

XPathNavigator createNavigator();

Creates an XPathNavigator for navigating this instance.

XmlNode createNode(XmlNodeType type, char[] name, char[] namespaceURI);

Creates an XmlNode with the specified type, name and namespaceURI.

Parameters
XmlNodeType type
The type of the new node.
char[] name
The qualified name of the new node.
char[] namespaceURI
The namespace URI of the new node.

Returns
The new XmlNode.

XmlNode createNode(XmlNodeType type, char[] prefix, char[] name, char[] namespaceURI);

Creates an XmlNode with the specified type, prefix, name and namespaceURI.

Parameters
XmlNodeType type
The type of the new node.
char[] prefix
The prefix of the new node.
char[] name
The local name of the new node.
char[] namespaceURI
The namespace URI of the new node.

Returns
The new XmlNode.

XmlElement createElement(char[] name);

Creates an XmlElement with the specified name.

Parameters
char[] name
The qualified name of the element.

Returns
The new XmlElement.

XmlElement createElement(char[] qualifiedName, char[] namespaceURI);

Creates an XmlElement with the specified name and namespaceURI.

Parameters
char[] qualifiedName
The qualified name of the element.
char[] namespaceURI
The namespace URI of the element.

Returns
The new XmlElement.

XmlElement createElement(char[] prefix, char[] localName, char[] namespaceURI);

Creates an XmlElement with the specified prefix, localName and namespaceURI.

Parameters
char[] prefix
The prefix of the element.
char[] localName
The local name of the element.
char[] namespaceURI
The namespace URI of the element.

Returns
The new XmlElement.

XmlAttribute createAttribute(char[] name);

Creates an XmlAttribute with the specified name.

Parameters
char[] name
The qualified name of the attribute.

Returns
The new XmlAttribute.

XmlAttribute createAttribute(char[] qualifiedName, char[] namespaceURI);

Creates an XmlAttribute with the specified name and namespaceURI.

Parameters
char[] qualifiedName
The qualified name of the attribute.
char[] namespaceURI
The namespace URI of the attribute.

Returns
The new XmlAttribute.

XmlAttribute createAttribute(char[] prefix, char[] localName, char[] namespaceURI);

Creates an XmlAttribute with the specified prefix, localName and namespaceURI.

Parameters
char[] prefix
The prefix of the attribute.
char[] localName
The local name of the attribute.
char[] namespaceURI
The namespace URI of the attribute.

Returns
The new XmlAttribute.

XmlCDataSection createCDataSection(char[] data);

Creates an XmlCDataSection node with the specified data.

Parameters
text
The data for the node.

Returns
The new XmlCDataSection node.

XmlComment createComment(char[] data);

Creates an XmlComment node with the specified data.

Parameters
text
The data for the node.

Returns
The new XmlComment node.

XmlText createTextNode(char[] text);

Creates an XmlText node with the specified text.

Parameters
char[] text
The text for the node.

Returns
The new XmlText node.

XmlProcessingInstruction createProcessingInstruction(char[] target, char[] data);

Creates an XmlProcessingInstruction node with the specified name and data.

Parameters
char[] target
the name of the processing instruction.
char[] data
The data for the processing instruction.

Returns
The new XmlProcessingInstruction node.

XmlDeclaration createXmlDeclaration(char[] xmlversion, char[] encoding, char[] standalone);

Create an XmlDeclaration node with the specified values.

Parameters
char[] xmlversion
The version must be "1.0".
char[] encoding
The value of the encoding attribute.
char[] standalone
The value must be either "yes" or "no".

Returns
The new XmlDeclaration node.

XmlEntityReference createEntityReference(char[] name);

Creates an XmlEntityReference with the specified name.

Parameters

Returns
The new XmlEntityReference.

XmlDocumentFragment createDocumentFragment();

Creates an XmlDocumentFragment.

Returns
The new XmlDocumentFragment.

void load(char[] fileName);

Loads the XML document from the specified URL.

Parameters
char[] fileName
URL for the file containing the XML document to load. The URL can be either a local file or a web address.

Throws
XmlException if there is a load or parse error in the XML.

void load(Stream input);

Loads the XML document from the specified stream.

Parameters
Stream input
The stream containing the XML document to load.

Throws
XmlException if there is a load or parse error in the XML.

void loadXml(char[] xml);

Loads the XML document from the specified string.

Parameters
char[] xml
The string containing the XML document to load.

Throws
XmlException if there is a load or parse error in the XML.

void save(char[] fileName);

Saves the XML document to the specified file.

Parameters
char[] fileName
The location of the file where you want to save the document.

Throws
XmlException if there is no document element.

void save(Stream output);

Saves the XML document to the specified stream.

Parameters
Stream output
The stream to which you want to save.

XmlElement getElementByTagId(char[] elementId);

Gets the XmlElement with the specified ID.

Parameters
char[] elementId
The attribute ID to match.

Returns
The XmlElement with the matching ID.

XmlElement documentElement();

Gets the root element for the document.

Returns
The XmlElement representing the root of the XML document tree. If no root exists, null is returned.

XmlNodeType nodeType();

Gets the type of the current node.

Returns
For XmlDocument nodes, the value is XmlNodeType.Document.

char[] localName();

Gets the locale name of the node.

Returns
For XmlDocument nodes, the local name is #document.

char[] name();

Gets the qualified name of the node.

Returns
For XmlDocument nodes, the name is #document.

XmlNode parentNode();

Gets the parent node.

Returns
For XmlDocument nodes, null is returned.

XmlDocument ownerDocument();

Gets the XmlDocument to which the current node belongs.

Returns
For XmlDocument nodes, null is returned.

void xml(char[] value);
char[] xml();

Gets or sets the markup representing the children of this node.

Returns
The markup of the children of this node.

final void preserveWhitespace(bool value);
final bool preserveWhitespace();

Gets or sets a value indicating whether to preserve white space in element content.

Parameters
bool value
true to preserve white space; otherwise, false.