XML article idhw titleHellotitle paraHello objectWorldobjectpara article article
XML <article id="hw"> <title>Hello</title> <para>Hello, <object>World</object>!</para> / </article> article “World”
<usr> <bin> <cat/> <echo/> <xmllint/> … </bin> <lib> … </lib> </usr>
<AAA> <XXX> <DDD> <BBB/> <EEE/> <FFF/> </DDD> </XXX> <CCC> <XXX> <BBB/> <EEE/> <FFF/> </XXX> </CCC> </AAA> * Любое имя /AAA/*/*/BBB
<AAA> <BBB id="b 1"/> <BBB id="b 2"/> <BBB name="bbb"/> <BBB/> </AAA> @ Атрибут //BBB/@name
Фильтрация (/AAA/BBB)[1] <AAA> <BBB/> </AAA> (/AAA/BBB)[last()] <AAA> <BBB/> </AAA>
Фильтрация, функции //bin[vim] //openssh[. //sshd[@date<20040923 //bin/*[contains(name(), 'vi')]
Пример XQuery <example> <p> Here is a query. </p> <eg> doc("books. xml")//book[1]/title </eg> <p> Here is the result of the above query. </p> <eg>{ doc("books. xml")//book[1]/title }</eg> <example> </example> <p> Here is a query. </p> <eg> doc("books. xml")//book[1]/title </eg> <p> Here is the result of the above query. </p> <eg><title>TCP/IP Illustrated</title></eg> </example>
FLWOR (“flower”) expressions for—let—where—order by—return for $i in (1, 2, 3) return <tuple><i>{ $i }</i></tuple> <tuple><i>1</i></tuple > <tuple><i>2</i></tuple > <tuple><i>3</i></tuple
Функции define function toc($book-or-section as element()) as element()* { for $section in $book-or-section/section return <section> { $section/@* , $section/title , toc($section) } </section> } <toc> { for $s in doc("xquery-book. xml")/book return toc($s) }
Ресурсы Спецификации http: //zvon. org/ А. Валиков “Технология XSLT” http: //xmlhack. ru/ “XQuery from the Experts: A Guide to the W 3 C XML Query Language” by Howard Katz, D. D. Chamberlin
XPath vs “вручную” for (; cur_node != null; cur_node = (from. End ? cur_node. get. Previous. Sibling() : cur_node. get. Next. Sibling ())) { // // Check that current node is of type 'element' // if (cur_node. get. Node. Type() != Node. ELEMENT_NODE) { continue; } // // Get element, check its name and position // Element cur_elem = (Element)cur_node; if ((name != null) && (! name. equals (cur_elem. get. Tag. Name()))) { continue; } cur_pos++; if (cur_pos == pos) { return cur_elem; } } // // If node was found, it was returned from inside loop // return null; } get_elem("elemname[i]") vs /** * Returns child element at given position. Position can be * negative. In this case nodes are counting from end. * Last node position is '-1'. * @param node parent node * @param name of node, null if not important * @param position of node starting from zero, can be negative */ public static Element get. Child. Element (Element node, String name, int s) { // // Update position to be always positive. // boolean from. End = pos < 0; if (from. End) { pos = -(pos + 1); } // // Initialize // Node cur_node = from. End ? node. get. Last. Child(): node. get. First. Child(); int cur_pos = -1; // // Walk on children //
SXML XML: <article id="hw"> <title>Hello</title> <para>Hello, <object>World</object>!</para> </article> S-exp: (*TOP* (article (@ (id "hw")) (title "Hello") (para "Hello, " (object "World") "!")))
SXPath ((txpath "//TAF/VALID/@TRange/text()") document) ((sxpath '(// TAF VALID @ TRange *text*)) document) ((node-join (node-closure (node-typeof? 'TAF)) (select-kids (node-typeof? 'VALID)) (select-kids (node-typeof? '@)) (select-kids (node-typeof? 'TRange)) (select-kids (node-typeof? '*text*))) document)
ВМ как исходный код e 1 : = _X(doc, “AAA//BBB/CCC”) e 2 : = _X(doc, “AAA//BBB/DDD”) t 1 : = child(doc, “AAA”) t 2 : = descendant(t 1, “BBB”) e 1 : = child(t 2, “CCC”) t 3 : = child(doc, “AAA”) t 4 : = descendant(t 3, “BBB”) e 2 : = child(t 4, “DDD”) t 1 : = child(doc, “AAA”) t 2 : = descendant(t 1, “BBB”) e 1 : = child(t 2, “CCC”) e 2 : = child(t 2, “DDD”)
Другие ВМ Java VM. NET VM LLVM
- Slides: 30