Returns an Array of Element
children. An XPath
may be supplied to filter the children. Only Element
children are returned, even if the supplied XPath
matches non-Element children.
doc = Document.new '<a>sean<b/>elliott<c/></a>' doc.root.elements.to_a #-> [ <b/>, <c/> ] doc.root.elements.to_a("child::node()") #-> [ <b/>, <c/> ] XPath.match(doc.root, "child::node()") #-> [ sean, <b/>, elliott, <c/> ]
Returns an array of Strings containing all of the prefixes declared by this set of # attributes. The array does not include the default namespace declaration, if one exists.
doc = Document.new("<a xmlns='foo' xmlns:x='bar' xmlns:y='twee' "+ "z='glorp' p:k='gru'/>") prefixes = doc.root.attributes.prefixes #-> ['x', 'y']
Evaluates to the unnormalized value of this entity; that is, replacing all entities – both %ent; and &ent; entities. This differs from +value()+ in that value
only replaces %ent; entities.
Returns the value of this entity unprocessed – raw. This is the normalized value; that is, with all %ent; and &ent; entities intact
Returns this entity as a string. See write().
A predicate filters a node-set with respect to an axis to produce a new node-set. For each node in the node-set to be filtered, the PredicateExpr is evaluated with that node as the context node, with the number of nodes in the node-set as the context size, and with the proximity position of the node in the node-set with respect to the axis as the context position; if PredicateExpr evaluates to true for that node, the node is included in the new node-set; otherwise, it is not included.
A PredicateExpr is evaluated by evaluating the Expr and converting the result to a boolean. If the result is a number, the result will be converted to true if the number is equal to the context position and will be converted to false otherwise; if the result is not a number, then the result will be converted as if by a call to the boolean function. Thus a location path para is equivalent to para.
Returns the string value of this text node. This string is always escaped, meaning that it is a valid XML
text node string, and all entities that can be escaped, have been inserted. This method respects the entity filter set in the constructor.
# Assume that the entity "s" is defined to be "sean", and that the # entity "r" is defined to be "russell" t = Text.new( "< & sean russell", false, nil, false, ['s'] ) t.to_s #-> "< & &s; russell" t = Text.new( "< & &s; russell", false, nil, false ) t.to_s #-> "< & &s; russell" u = Text.new( "sean russell", false, nil, true ) u.to_s #-> "sean russell"
Escapes all possible entities
Unescapes all possible entities
Finds and returns the first node that matches the supplied xpath.
The context element
The xpath to search for. If not supplied or nil, returns the first node matching ‘*’.
If supplied, a Hash
which defines a namespace mapping.
If supplied, a Hash
which maps $variables in the query to values. This can be used to avoid XPath
injection attacks or to automatically handle escaping string values.
XPath.first( node ) XPath.first( doc, "//b"} ) XPath.first( node, "a/x:b", { "x"=>"http://doofus" } ) XPath.first( node, '/book/publisher/text()=$publisher', {}, {"publisher"=>"O'Reilly"})
Performs a depth-first (document order) XPath
search, and returns the first match. This is the fastest, lightest way to return a single result.
FIXME: This method is incomplete!
Builds a nodeset of all of the preceding nodes of the supplied node, in reverse document order
includes every element in the document that precedes this node,
except for ancestors