www.digitalmars.com

D Programming Language 2.0

Last update Sat Apr 7 20:59:05 2012

arsd.dom

This is an html DOM implementation, started with cloning what the browser offers in Javascript, but going well beyond it in convenience.

If you can do it in Javascript, you can probably do it with this module.

And much more.

Note:
some of the documentation here writes html with added spaces. That's because ddoc doesn't bother encoding html output, and adding spaces is easier than using LT macros everywhere.

BTW:
this file depends on arsd.characterencodings, so help it correctly read files from the internet. You should be able to get characterencodings.d from the same place you got this file.

abstract interface FileResource;
This might belong in another module, but it represents a file with a mime type and some data. Document implements this interface with type = text/html (see Document.contentType for more info) and data = document.toString, so you can return Documents anywhere web.d expects FileResources.

abstract const string contentType();
the content-type of the file. e.g. "text/html; charset=utf-8" or "image/png"

abstract const immutable(ubyte)[] getData();
the data

struct DataSet;
A proxy object to do the Element class' dataset property. See Element.dataset for more info.

Do not create this object directly.

struct ElementStyle;
for style, i want to be able to set it with a string like a plain attribute, but also be able to do properties Javascript style.

enum NodeType;
.

T require(T = Element, string file = __FILE__, int line = __LINE__)(Element e);
You can use this to do an easy null check or a dynamic cast+null check on any element.

class Element;
This represents almost everything in the DOM.

string tagName;
The name of the tag. Remember, changing this doesn't change the dynamic type of the object.

string[string] attributes;
This is where the attributes are actually stored. You should use getAttribute, setAttribute, and hasAttribute instead.

Document parentDocument;
Get the parent Document object that contains this element. It may be null, so remember to check for that.

Element parentNode;
.

static Element make(string tagName, string childInfo = null, string childInfo2 = null);
Convenience function to try to do the right thing for HTML. This is the main way I create elements.

this(Document _parentDocument, string _tagName, string[string] _attributes = null, bool _selfClosed = false);
Generally, you don't want to call this yourself - use Element.make or document.createElement instead.

this(string _tagName, string[string] _attributes = null);
Convenience constructor when you don't care about the parentDocument. Note this might break things on the document. Note also that without a parent document, elements are always in strict, case-sensitive mode.

@property Element firstChild();
Returns the first child of this element. If it has no children, returns null. Remember, text nodes are children too.

@property Element lastChild();

@property Element previousSibling(string tagName = null);
.

@property Element nextSibling(string tagName = null);
.

T getParent(T = Element)(string tagName = null);
Gets the nearest node, going up the chain, with the given tagName May return null or throw.

Element getElementById(string id);
.

SomeElementType requireElementById(SomeElementType = Element, string file = __FILE__, int line = __LINE__)(string id);
.

SomeElementType requireSelector(SomeElementType = Element, string file = __FILE__, int line = __LINE__)(string selector);
.

Element querySelector(string selector);
Note:
you can give multiple selectors, separated by commas. It will return the first match it finds.

Element[] querySelectorAll(string selector);
a more standards-compliant alias for getElementsBySelector

Element[] getElementsBySelector(string selector);
Does a CSS selector

-- all, default if nothing else is there

tag#id.class.class.class:pseudo[attrib=what][attrib=what] OP selector

It is all additive

OP

space = descendant > = direct descendant + = sibling (E+F Matches any F element immediately preceded by a sibling element E)

[foo] Foo is present as an attribute [foo="warning"] Matches any E element whose "foo" attribute value is exactly equal to "warning". E[foo~="warning"] Matches any E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "warning" E[lang|="en"] Matches any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en".

[item$=sdas] ends with [item^-sdsad] begins with

Quotes are optional here.

Pseudos:
:first-child :last-child :link (same as a[href] for our purposes here)

There can be commas separating the selector. A comma separated list result is OR'd onto the main.

This ONLY cares about elements. text, etc, are ignored

There should be two functions: given element, does it match the selector? and given a selector, give me all the elements

Element[] getElementsByClassName(string cn);
.

Element[] getElementsByTagName(string tag);
.

const string getAttribute(string name);
Gets the given attribute value, or null if the attribute is not set.

Note that the returned string is decoded, so it no longer contains any xml entities.

Element setAttribute(string name, string value);
Sets an attribute. Returns this for easy chaining

bool hasAttribute(string name);
Returns if the attribute exists.

Element removeAttribute(string name);
Removes the given attribute from the element.

const string className();
Gets the class attribute's contents. Returns an empty string if it has no class.

Element className(string c);
.

string opDispatch(string name)(string v = null);
Provides easy access to attributes, object style.

auto element = Element.make("a"); a.href = "cool.html"; // this is the same as a.setAttribute("href", "cool.html"); string where = a.href; // same as a.getAttribute("href");

const @property const(Element[]) childNodes();
Returns the element's children.

@property Element[] childNodes();
Mutable version of the same

@property string[] classes();
get all the classes on this element

Element addClass(string c);
Adds a string to the class attribute. The class attribute is used a lot in CSS.

Element removeClass(string c);
Removes a particular class name.

bool hasClass(string c);
Returns whether the given class appears in this element.

DataSet dataset();
HTML5's dataset property. It is an alternate view into attributes with the data- prefix.

Given:

We get: assert(a.
dataset.myProperty == "cool");

@property ElementStyle style();
Provides both string and object style (like in Javascript) access to the style attribute.

@property ElementStyle style(string s);
This sets the style attribute with a string.

@property CssStyle computedStyle();
.

void removeAllChildren();
Removes all inner content from the tag; all child text and elements are gone.

Element addChild(string tagName, string childInfo = null, string childInfo2 = null);
convenience function to quickly add a tag with some text or other relevant info (for example, it's a src for an element instead of inner text)

Element addSibling(string tagName, string childInfo = null, string childInfo2 = null);
Another convenience function. Adds a child directly after the current one, returning the new child.

Between this, addChild, and parentNode, you can build a tree as a single expression.

void addChildren(T...)(T t);
Convenience function to append text intermixed with other children. For example: div.addChildren("You can visit my website by ", new Link("mysite.com", "clicking here"), "."); or div.addChildren("Hello, ", user.name, "!"); See also: appendHtml. This might be a bit simpler though because you don't have to think about escaping.

Element addChild(string tagName, Element firstChild);
.

Element appendChild(Element e);
Appends the given element to this one. The given element must not have a parent already.

void appendChildren(Element[] children);
.

Element insertBefore(in Element where, Element what);
Inserts the second element to this node, right before the first param

Element insertAfter(in Element where, Element what);
.

Element swapNode(Element child, Element replacement);
swaps one child for a new thing. Returns the old child which is now parentless.

Element appendText(string text);
.

@property Element[] childElements();
.

Element[] appendHtml(string html);
Appends the given html to the element, returning the elements appended

void reparent(Element newParent);
.

void insertChildAfter(Element child, Element where);
.

Element[] stealChildren(Element e, Element position = null);
.

Element prependChild(Element e);
Puts the current element first in our children list. The given element must not have a parent already.

const @property string innerHTML(Appender!(string) where = appender(null));
Returns a string containing all child elements, formatted such that it could be pasted into an XML file.

@property void innerHTML(string html);
@property void innerHTML(Html html);
Takes some html and replaces the element's children with the tree made from the string.

@property Element[] outerHTML(string html);
Replaces this node with the given html string, which is parsed

Note:
this invalidates the this reference, since it is removed from the tree.

Returns the new children that replace this.

@property string outerHTML();
Returns all the html for this element, including the tag itself. This is equivalent to calling toString().

@property void innerRawSource(string rawSource);
This sets the inner content of the element *without* trying to parse it. You can inject any code in there; this serves as an escape hatch from the dom.

The only times you might actually need it are for < style > and < script > tags in html. Other than that, innerHTML and/or innerText should do the job.

Element replaceChild(Element find, Element replace);
.

Element removeChild(Element c);
Removes the given child from this list.

Returns the removed element.

Element[] removeChildren();
This removes all the children from this element, returning the old list.

void replaceChild(Element find, Element[] replace);
Replaces the given element with a whole group.

void stripOut();
Strips this tag out of the document, putting its inner html as children of the parent.

For example, given:

hello there

, if you call stripOut() on the b element, you'll be left with

hello there

.

The idea here is to make it easy to get rid of garbage markup you aren't interested in.

Element removeFromTree();
shorthand for this.parentNode.removeChild(this) with parentNode null check if the element already isn't in a tree, it does nothing.

Element wrapIn(Element what);
Wraps this element inside the given element. It's like this.replaceWith(what); what.appendchild(this);

Given:
< b >cool</ b >, if you call b.wrapIn(new Link("site.com", "my site is ")); you'll end up with: < a href="site.com">my site is < b >cool< /b ></ a >.

Element replaceWith(Element e);
Replaces this element with something else in the tree.

const string[] classNames();
Splits the className into an array of each class given

const string firstInnerText();
Fetches the first consecutive nodes, if text nodes, concatenated together

If the first node is not text, returns null.

See also: directText, innerText

const @property string innerText();
Fetch the inside text, with all tags stripped out.

cool api & code dude

innerText of that is "cool api & code dude".

@property void innerText(string text);
Sets the inside text, replacing all children. You don't have to worry about entity encoding.

@property string directText();
Returns the text directly under this element, not recursively like innerText.

See also: firstInnerText

@property void directText(string text);
Sets the direct text, keeping the same place.

Unlike innerText, this does *not* remove existing elements in the element.

It only replaces the first text node it sees.

If there are no text nodes, it calls appendText

So, given (ignore the spaces in the tags): < div > < img > text here < /div >

it will keep the img, and replace the "text here".

@property void outerText(string text);
Strips this node out of the document, replacing it with the given text

const @property string outerText();
Same result as innerText; the tag with all inner tags stripped out

@property Element cloned();
This is a full clone of the element

Element cloneNode(bool deepClone);
Clones the node. If deepClone is true, clone all inner tags too. If false, only do this tag (and its attributes), but it will have no contents.

const string nodeValue();
.

const @property int nodeType();
.

const string toString();
Turns the whole element, including tag, attributes, and children, into a string which could be pasted into an XML file.

const string writeToAppender(Appender!(string) where = appender(null));
This is the actual implementation used by toString. You can pass it a preallocated buffer to save some time. Returns the string it creates.

@property ElementStream tree();
Returns a lazy range of all its children, recursively.

class DocumentFragment: arsd.dom.Element;
.

this(Document _parentDocument);
.

const string writeToAppender(Appender!(string) where = appender(null));
.

string htmlEntitiesEncode(string data, Appender!(string) output = appender(null));
Given text, encode all html entities on it - &, <, >, and ". This function also encodes all 8 bit characters as entities, thus ensuring the resultant text will work even if your charset isn't set right.

The output parameter can be given to append to an existing buffer. You don't have to pass one; regardless, the return value will be usable for you, with just the data encoded.

string xmlEntitiesEncode(string data);
An alias for htmlEntitiesEncode; it works for xml too

dchar parseEntity(in dchar[] entity);
This helper function is used for decoding html entities. It has a hard-coded list of entities and characters.

string htmlEntitiesDecode(string data, bool strict = false);
This takes a string of raw HTML and decodes the entities into a nice D utf-8 string. By default, it uses loose mode - it will try to return a useful string from garbage input too. Set the second parameter to true if you'd prefer it to strictly throw exceptions on garbage input.

class RawSource: arsd.dom.Element;
.

this(Document _parentDocument, string s);
.

const string nodeValue();
.

const int nodeType();
.

const string writeToAppender(Appender!(string) where = appender(null));
.

Element appendChild(Element e);
.

string source;
.

class TextNode: arsd.dom.Element;
.

this(Document _parentDocument, string e);
.

static TextNode fromUndecodedString(Document _parentDocument, string html);
.

@property Element cloned();
.

const string nodeValue();
.

const int nodeType();
.

const string writeToAppender(Appender!(string) where = appender(null));
.

Element appendChild(Element e);
.

string contents;
.

class Link: arsd.dom.Element;
There are subclasses of Element offering improved helper functions for the element in HTML. .

this(Document _parentDocument);
.

this(string href, string text);
.

string getValue(string name);
This gets a variable from the URL's query string.

void updateQueryString(string[string] vars);
.

void setValue(string name, string variable);
Sets or adds the variable with the given name to the given value It automatically URI encodes the values and takes care of the ? and &.

void removeValue(string name);
Removes the given variable from the query string

class Form: arsd.dom.Element;
.

this(Document _parentDocument);
.

void setValue(string field, string value, bool makeNew = true);
Set's the form field's value. For input boxes, this sets the value attribute. For textareas, it sets the innerText. For radio boxes and select boxes, it removes the checked/selected attribute from all, and adds it to the one matching the value. For checkboxes, if the value is non-null and not empty, it checks the box. If you set a value that doesn't exist, it throws an exception if makeNew is false. Otherwise, it makes a new input with type=hidden to keep the value.

void addValueArray(string key, string[] arrayOfValues);
This takes an array of strings and adds hidden elements for each one of them. Unlike setValue, it makes no attempt to find and modify existing elements in the form to the new values.

string getValue(string field);
Gets the value of the field; what would be given if it submitted right now. (so it handles select boxes and radio buttons too). For checkboxes, if a value isn't given, but it is checked, it returns "checked", since null and "" are indistinguishable

string getPostableData();
.

Element[] getField(string name);
Gets the actual elements with the given name

Element getLabel(string forId);
Grabs the
Element addField(string name, string value, string type = "hidden");
Adds a new INPUT field to the end of the form with the given attributes.

void removeField(string name);
Removes the given field from the form. It finds the element and knocks it right out.

class Table: arsd.dom.Element;
.

this(Document _parentDocument);
.

Element th(T)(T t);
.

Element td(T)(T t);
.

Element appendRow(T...)(T t);
.

Element captionElement();
.

@property string caption();
.

@property void caption(string text);
.

TableCell[][] getGrid(Element tablePortition = null);
Gets the logical layout of the table as a rectangular grid of cells. It considers rowspan and colspan. A cell with a large span is represented in the grid by being referenced several times. The tablePortition parameter can get just a , , or portion if you pass one.

Note:
the rectangular grid might include null cells.

This is kinda expensive so you should call once when you want the grid, then do lookups on the returned array.

class TableRow: arsd.dom.Element;
Represents a table row element - a

this(Document _parentDocument);
.

class TableCell: arsd.dom.Element;
Represents anything that can be a table cell - or html.

this(Document _parentDocument, string _tagName);
.

class MarkupError: object.Exception;
.

this(string message);
.

class ElementNotFoundException: object.Exception;
This is used when you are using one of the require variants of navigation, and no matching element can be found in the tree.

this(string type, string search, string file = __FILE__, int line = __LINE__);
type == kind of element you were looking for and search == a selector describing the search.

struct Html;
The html struct is used to differentiate between regular text nodes and html in certain functions

Easiest way to construct it is like this: auto html = Html("

hello

");

string source;
This string holds the actual html. Use it to retrieve the contents.

class Document: arsd.dom.FileResource;
The main document interface, including a html parser.

this(string data, bool caseSensitive = false, bool strict = false);
.

this();
Creates an empty document. It has *nothing* in it at all.

ElementCollection opIndex(string selector);
This is just something I'm toying with. Right now, you use opIndex to put in css selectors. It returns a struct that forwards calls to all elements it holds, and returns itself so you can chain it.

Example:
document["p"].innerText("hello").addClass("modified");

Equivalent to: foreach(e; document.getElementsBySelector("p")) { e.innerText("hello"); e.addClas("modified"); }

Note:
always use function calls (not property syntax) and don't use toString in there for best results.

You can also do things like: document["p"]["b"] though tbh I'm not sure why since the selector string can do all that anyway. Maybe you could put in some kind of custom filter function tho.

string contentType(string mimeType);
If you're using this for some other kind of XML, you can set the content type here.

Note:
this has no impact on the function of this class. It is only used if the document is sent via a protocol like HTTP.

This may be called by parse() if it recognizes the data. Otherwise, if you don't set it, it assumes text/html; charset=utf-8.

const string contentType();
implementing the FileResource interface, useful for sending via http automatically.

const immutable(ubyte)[] getData();
implementing the FileResource interface; it calls toString.

void parseGarbage(string data);
Concatenates any consecutive text nodes Given the kind of garbage you find on the Internet, try to make sense of it. Equivalent to document.parse(data, false, false, null); (Case-insensitive, non-strict, determine character encoding from the data.)

NOTE:
this makes no attempt at added security.

void parse(in string rawdata, bool caseSensitive = false, bool strict = false, string dataEncoding = "UTF-8");
Take XMLish data and try to make the DOM tree out of it.

The goal isn't to be perfect, but to just be good enough to approximate Javascript's behavior.

If strict, it throws on something that doesn't make sense. (Examples: mismatched tags. It doesn't validate!) If not strict, it tries to recover anyway, and only throws when something is REALLY unworkable.

If strict is false, it uses a magic list of tags that needn't be closed. If you are writing a document specifically for this, try to avoid such - use self closed tags at least. Easier to parse.

The dataEncoding argument can be used to pass a specific charset encoding for automatic conversion. If null (which is NOT the default!), it tries to determine from the data itself, using the xml prolog or meta tags, and assumes UTF-8 if unsure.

If this assumption is wrong, it can throw on non-ascii characters!

Note that it previously assumed the data was encoded as UTF-8, which is why the dataEncoding argument defaults to that.

So it shouldn't break backward compatibility.

But, if you want the best behavior on wild data - figuring it out from the document instead of assuming - you'll probably want to change that argument to null.

@property string title();
Gets the element's innerText, if one exists<p></p> </dd> <dt><div class="d_decl">@property void <a name="title"></a><u>title</u>(string <i>t</i>); </div></dt> <dd>Sets the <a name="title"></a><u>title</u> of the page, creating a <title> element if needed.<p></p> </dd> <dt><div class="d_decl">Element <a name="getElementById"></a><u>getElementById</u>(string <i>id</i>); <br>SomeElementType <a name="requireElementById"></a><u>requireElementById</u>(SomeElementType = Element)(string <i>id</i>); <br>SomeElementType <a name="requireSelector"></a><u>requireSelector</u>(SomeElementType = Element, string file = __FILE__, int line = __LINE__)(string <i>selector</i>); <br>Element <a name="querySelector"></a><u>querySelector</u>(string <i>selector</i>); <br>Element[] <a name="querySelectorAll"></a><u>querySelectorAll</u>(string <i>selector</i>); <br>Element[] <a name="getElementsBySelector"></a><u>getElementsBySelector</u>(string <i>selector</i>); <br>Element[] <a name="getElementsByTagName"></a><u>getElementsByTagName</u>(string <i>tag</i>); </div></dt> <dd>These functions all forward to the root element. See the documentation in the Element class.<p></p> </dd> <dt><div class="d_decl">Element <a name="getFirstElementByTagName"></a><u>getFirstElementByTagName</u>(string <i>tag</i>); </div></dt> <dd><b>FIXME:</b><br> btw, this could just be a lazy range...... <p></p> </dd> <dt><div class="d_decl">Element <a name="mainBody"></a><u>mainBody</u>(); </div></dt> <dd>This returns the <body> element, if there is one. (It different than Javascript, where it is called 'body', because body is a keyword in D.)<p></p> </dd> <dt><div class="d_decl">string <a name="getMeta"></a><u>getMeta</u>(string <i>name</i>); </div></dt> <dd>this uses a weird thing... it's [<i>name</i>=] if no colon and [property=] if colon<p></p> </dd> <dt><div class="d_decl">void <a name="setMeta"></a><u>setMeta</u>(string <i>name</i>, string <i>value</i>); </div></dt> <dd>Sets a meta tag in the document header. It is kinda hacky to work easily for both Facebook open graph and traditional html meta tags/<p></p> </dd> <dt><div class="d_decl">Form[] <a name="forms"></a><u>forms</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Form <a name="createForm"></a><u>createForm</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element <a name="createElement"></a><u>createElement</u>(string <i>name</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element <a name="createFragment"></a><u>createFragment</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element <a name="createTextNode"></a><u>createTextNode</u>(string <i>content</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element <a name="findFirst"></a><u>findFirst</u>(bool delegate(Element) <i>doesItMatch</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">void <a name="clear"></a><u>clear</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">void <a name="setProlog"></a><u>setProlog</u>(string <i>d</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="prolog"></a><u>prolog</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">const string <a name="toString"></a><u>toString</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element <a name="root"></a><u>root</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="loose"></a><u>loose</u>; </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">class <a name="XmlDocument"></a><u>XmlDocument</u>: arsd.dom.Document; </div></dt> <dd>Specializes Document for handling generic XML. (always uses strict mode, uses xml mime type and file header)<p></p> </dd> <dt><div class="d_decl">int <a name="intFromHex"></a><u>intFromHex</u>(string <i>hex</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">static immutable string[] <a name="selectorTokens"></a><u>selectorTokens</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">sizediff_t <a name="idToken"></a><u>idToken</u>(string <i>str</i>, sizediff_t <i>position</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string[] <a name="lexSelector"></a><u>lexSelector</u>(string <i>selector</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">struct <a name="SelectorPart"></a><u>SelectorPart</u>; </div></dt> <dd>.<p></p> <dl><dt><div class="d_decl">string <a name="tagNameFilter"></a><u>tagNameFilter</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string[] <a name="attributesPresent"></a><u>attributesPresent</u>; </div></dt> <dd>[attr]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesEqual"></a><u>attributesEqual</u>; </div></dt> <dd>[attr=value]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesStartsWith"></a><u>attributesStartsWith</u>; </div></dt> <dd>[attr^=value]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesEndsWith"></a><u>attributesEndsWith</u>; </div></dt> <dd>[attr$=value]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesIncludesSeparatedBySpaces"></a><u>attributesIncludesSeparatedBySpaces</u>; </div></dt> <dd>[attr~=value]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesIncludesSeparatedByDashes"></a><u>attributesIncludesSeparatedByDashes</u>; </div></dt> <dd>[attr|=value]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesInclude"></a><u>attributesInclude</u>; </div></dt> <dd>[attr*=value]<p></p> </dd> <dt><div class="d_decl">string[2u][] <a name="attributesNotEqual"></a><u>attributesNotEqual</u>; </div></dt> <dd>[attr!=value] -- extension by me<p></p> </dd> <dt><div class="d_decl">bool <a name="firstChild"></a><u>firstChild</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="lastChild"></a><u>lastChild</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="emptyElement"></a><u>emptyElement</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="oddChild"></a><u>oddChild</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="evenChild"></a><u>evenChild</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="rootElement"></a><u>rootElement</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">int <a name="separation"></a><u>separation</u>; </div></dt> <dd>-1 == only itself; the <b>null</b> selector, 0 == tree, 1 == childNodes, 2 == childAfter, 3 == youngerSibling, 4 == parentOf<p></p> </dd> <dt><div class="d_decl">string <a name="toString"></a><u>toString</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="matchElement"></a><u>matchElement</u>(Element <i>e</i>); </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">Element[] <a name="getElementsBySelectorParts"></a><u>getElementsBySelectorParts</u>(Element <i>start</i>, SelectorPart[] <i>parts</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">struct <a name="Selector"></a><u>Selector</u>; </div></dt> <dd>.<p></p> <dl><dt><div class="d_decl">SelectorPart[] <a name="parts"></a><u>parts</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="toString"></a><u>toString</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element[] <a name="getElements"></a><u>getElements</u>(Element <i>start</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="matchElement"></a><u>matchElement</u>(Element <i>e</i>, Element <i>relativeTo</i> = null); </div></dt> <dd>If <i>relativeTo</i> == <b>null</b>, it assumes the root of the parent document.<p></p> </dd> <dt><div class="d_decl">static Selector <a name="fromString"></a><u>fromString</u>(string <i>selector</i>); </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">Selector[] <a name="parseSelectorString"></a><u>parseSelectorString</u>(string <i>selector</i>, bool <i>caseSensitiveTags</i> = true); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Selector <a name="parseSelector"></a><u>parseSelector</u>(string[] <i>tokens</i>, bool <i>caseSensitiveTags</i> = true); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Element[] <a name="removeDuplicates"></a><u>removeDuplicates</u>(Element[] <i>input</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="unCamelCase"></a><u>unCamelCase</u>(string <i>a</i>); </div></dt> <dd>Converts <i>a</i> camel cased propertyName to <i>a</i> css style dashed property-name<p></p> </dd> <dt><div class="d_decl">string <a name="camelCase"></a><u>camelCase</u>(string <i>a</i>); </div></dt> <dd>Translates <i>a</i> css style property-name to <i>a</i> camel cased propertyName<p></p> </dd> <dt><div class="d_decl">class <a name="CssStyle"></a><u>CssStyle</u>; </div></dt> <dd>This is probably not useful to you unless you're writing a browser or something like that. It represents a *computed* style, like what the browser gives you after applying stylesheets, inline styles, and html attributes. From here, you can start to make a layout engine for the box model and have a css aware browser.<p></p> <dl><dt><div class="d_decl">this(string <i>rule</i>, string <i>content</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Specificity <a name="getSpecificityOfRule"></a><u>getSpecificityOfRule</u>(string <i>rule</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="originatingRule"></a><u>originatingRule</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Specificity <a name="originatingSpecificity"></a><u>originatingSpecificity</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">union <a name="Specificity"></a><u>Specificity</u>; </div></dt> <dd>.<p></p> <dl><dt><div class="d_decl">uint <a name="score"></a><u>score</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">ubyte <a name="tags"></a><u>tags</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">ubyte <a name="classes"></a><u>classes</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">ubyte <a name="ids"></a><u>ids</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">ubyte <a name="important"></a><u>important</u>; </div></dt> <dd>0 = none, 1 = stylesheet author, 2 = inline style, 3 = user <a name="important"></a><u>important</u> .<p></p> </dd> </dl> </dd> <dt><div class="d_decl">struct <a name="Property"></a><u>Property</u>; </div></dt> <dd>.<p></p> <dl><dt><div class="d_decl">bool <a name="givenExplicitly"></a><u>givenExplicitly</u>; </div></dt> <dd>this is <b>false</b> if for example the user said "padding" and this is "padding-left"<p></p> </dd> <dt><div class="d_decl">string <a name="name"></a><u>name</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="value"></a><u>value</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">Specificity <a name="specificity"></a><u>specificity</u>; </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">Property[] <a name="properties"></a><u>properties</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="opDispatch"></a><u>opDispatch</u>(string nameGiven)(string <i>value</i> = null); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="getValue"></a><u>getValue</u>(string <i>name</i>); </div></dt> <dd>takes dash style <i>name</i><p></p> </dd> <dt><div class="d_decl">string <a name="setValue"></a><u>setValue</u>(string <i>name</i>, string <i>value</i>, Specificity <i>newSpecificity</i>, bool <i>explicit</i> = true); </div></dt> <dd>takes dash style <i>name</i><p></p> </dd> <dt><div class="d_decl">void <a name="expandShortForm"></a><u>expandShortForm</u>(Property <i>p</i>, Specificity <i>specificity</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">string <a name="toString"></a><u>toString</u>(); </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">class <a name="StyleSheet"></a><u>StyleSheet</u>; </div></dt> <dd>This probably isn't useful, unless you're writing a browser or something like that. You might want to look at arsd.html for css macro, nesting, etc., or just use standard css as text. <p></p> The idea, however, is to represent a kind of CSS object model, complete with specificity, that you can apply to your documents to build the complete computedStyle object.<p></p> <dl><dt><div class="d_decl">CssStyle[] <a name="rules"></a><u>rules</u>; </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">this(string <i>source</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">void <a name="apply"></a><u>apply</u>(Document <i>document</i>); </div></dt> <dd>Run through the <i>document</i> and <a name="apply"></a><u>apply</u> this stylesheet to it. The computedStyle member will be accurate after this call<p></p> </dd> </dl> </dd> <dt><div class="d_decl">class <a name="Stack"></a><u>Stack</u>(T); </div></dt> <dd>This is kinda private; just a little utility container for use by the ElementStream class.<p></p> <dl><dt><div class="d_decl">void <a name="push"></a><u>push</u>(T <i>t</i>); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">T <a name="pop"></a><u>pop</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">T <a name="peek"></a><u>peek</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">bool <a name="empty"></a><u>empty</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">T[] <a name="arr"></a><u>arr</u>; </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">class <a name="ElementStream"></a><u>ElementStream</u>; </div></dt> <dd>This is the lazy range that walks the tree for you. It tries to go in the lexical order of the source: node, then children from first to last, each recursively.<p></p> <dl><dt><div class="d_decl">@property Element <a name="front"></a><u>front</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">this(Element <i>start</i>); </div></dt> <dd>Use Element.tree instead.<p></p> </dd> <dt><div class="d_decl">void <a name="popFront"></a><u>popFront</u>(); </div></dt> <dd>.<p></p> </dd> <dt><div class="d_decl">void <a name="currentKilled"></a><u>currentKilled</u>(); </div></dt> <dd>You should call this when you remove an element from the tree. It then doesn't recurse into that node and adjusts the current position, keeping the range stable.<p></p> </dd> <dt><div class="d_decl">@property bool <a name="empty"></a><u>empty</u>(); </div></dt> <dd>.<p></p> </dd> </dl> </dd> <dt><div class="d_decl">alias <a name="EventHandler"></a><u>EventHandler</u>; </div></dt> <dd>used for DOM events<p></p> </dd> <dt><div class="d_decl">class <a name="Event"></a><u>Event</u>; </div></dt> <dd>This is a DOM event, like in javascript. Note that this library never fires events - it is only here for you to use if you want it.<p></p> <dl><dt><div class="d_decl">void <a name="preventDefault"></a><u>preventDefault</u>(); </div></dt> <dd>Prevents the default event handler (if there is one) from being called<p></p> </dd> <dt><div class="d_decl">void <a name="stopPropagation"></a><u>stopPropagation</u>(); </div></dt> <dd>Stops the event propagation immediately.<p></p> </dd> <dt><div class="d_decl">void <a name="send"></a><u>send</u>(); </div></dt> <dd>this sends it only to the target. If you want propagation, use dispatch() instead.<p></p> </dd> <dt><div class="d_decl">void <a name="dispatch"></a><u>dispatch</u>(); </div></dt> <dd>this dispatches the element using the capture -> target -> bubble process<p></p> </dd> </dl> </dd> </dl> <br><br> <br><br> <!-- Google ad --> <script type="text/javascript"><!-- /**/google_ad_client = "pub-5628673096434613"; /**/google_ad_width = 728; /**/google_ad_height = 90; /**/google_ad_format = "728x90_as"; /**/google_ad_channel ="6203743411"; /**/google_page_url = document.location; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> <div id="copyright"> Copyright © 1999-2012 by Digital Mars, All Rights Reserved | Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </div> </body> </html>