Skip to content

AnnoMods.BBDom: LookUps

taubenangriff edited this page Mar 13, 2024 · 4 revisions

Node Lookups

using AnnoMods.BBDom.LookUps;

Importing the Namespace will give you the option to run very primitive and simple Node Lookups by Node Names in the DOM structure.

New Methods

These Lookup methods can be run on any BBDocument, Tag, or on any IEnumerable<BBNode>.

//Selects a Collection of Nodes that match the lookup
IEnumerable<BBNode> SelectNodes(String Lookup);
//Selects a Collection of Nodes that match the lookup and the provided LookupCondition
IEnumerable<BBNode> SelectNodes(String Lookup, LookupCondition condition);
//Selects the first Node matching the Lookup
BBNode SelectSingleNode(String Lookup);
//Selects the first Node matching the Lookup and the provided LookupCondition
BBNode SelectSingleNode(String Lookup, LookupCondition condition)

Lookup Paths

Lookups always start at the node you call them on, In case of a document, at root level. Lookup work by node name, seperated by /. Contrary to Xpath, there is no leading /, you begin the lookup right with the first node name.

There is no support for regex, pattern matching or similar whatsoever, just plain node names.

Sample Lookup

Root1
    ChildA
        ChildChildA
    ChildB
    ChildC
        ChildChildB
        ChildChildB
        ChildChildB

In the above Node Structure "document", you can look up ChildA with:

document.SelectSingleNode("Root1/ChildA");

You can also select all Nodes matching a pattern at once:

document.SelectNodes("Root1/ChildC/ChildChildB")

This will select all three ChildChildB nodes.

Lookup Filters

There are overloads for SelectNodes and SelectSingleNode taking in a delegate function bool LookupCondition(BBNode node) so you can pass in your own per-node-filtering functions like in the following example:

SelectNodes(Collection, Lookup, node => node.GetName().Equals("None") && node is Tag)

This will select all Tags named None