summaryrefslogtreecommitdiff
path: root/lib/xmerl/test/xmerl_SUITE_data/xpath
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xmerl/test/xmerl_SUITE_data/xpath')
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/documentRoot.xml43
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/e1074.xml18
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/e1075.xml18
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/e1076.xml13
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/e1077.xml16
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/e1078.xml11
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/motorcycles.xml25
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/myBS_model.xml6
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/purchaseOrder.xml36
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/xpath.xml25
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_abbrev.erl266
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_lib.erl184
-rw-r--r--lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_text.erl28
13 files changed, 689 insertions, 0 deletions
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/documentRoot.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/documentRoot.xml
new file mode 100644
index 0000000000..667a44b7fe
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/documentRoot.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<documentRoot>
+<!-- Test data from
+ http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm -->
+<?value ="2"?>
+<parent name="data" >
+ <child id="1" name="alpha" >Some Text</child>
+ <child id="2" name="beta" >
+ <grandchild id="2.1" name="beta-alpha" ></grandchild>
+ <grandchild id="2.2" name="beta-beta" ></grandchild>
+ </child>
+ <pet name="tigger" type="cat" >
+ <data>
+ <birthday month="sept" day="19" ></birthday>
+ <food name="Acme Cat Food" ></food>
+ </data>
+ </pet>
+ <pet name="Fido" type="dog" >
+ <description>
+ Large dog!
+ </description>
+ <data>
+ <birthday month="feb" day="3" ></birthday>
+ <food name="Acme Dog Food" ></food>
+ </data>
+ </pet>
+ <rogue name="is this real?" >
+ <data>
+ Hates dogs!
+ </data>
+ </rogue>
+ <child id="3" name="gamma" mark="yes" >
+ <!-- A comment -->
+ <description>
+ Likes all animals - especially dogs!
+ </description>
+ <grandchild id="3.1" name="gamma-alpha" >
+ <![CDATA[ Some non-parsable character data ]]>
+ </grandchild>
+ <grandchild id="3.2" name="gamma-beta" ></grandchild>
+ </child>
+</parent>
+</documentRoot> \ No newline at end of file
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/e1074.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1074.xml
new file mode 100644
index 0000000000..920a9e67e1
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1074.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <root id="1">
+ <elem1 id="2">
+ <elem2 id="3">
+ <e id="4"/>
+ <elem3 id="5">
+ <e id="6"/>
+ </elem3>
+ <elem3 id="7"/>
+ </elem2>
+ </elem1>
+ <elem1 id="8">
+ <elem2 id="9"/>
+ <e id="10"/>
+ <e id="11"/>
+ </elem1>
+ <e id="12"/>
+ </root>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/e1075.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1075.xml
new file mode 100644
index 0000000000..920a9e67e1
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1075.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <root id="1">
+ <elem1 id="2">
+ <elem2 id="3">
+ <e id="4"/>
+ <elem3 id="5">
+ <e id="6"/>
+ </elem3>
+ <elem3 id="7"/>
+ </elem2>
+ </elem1>
+ <elem1 id="8">
+ <elem2 id="9"/>
+ <e id="10"/>
+ <e id="11"/>
+ </elem1>
+ <e id="12"/>
+ </root>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/e1076.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1076.xml
new file mode 100644
index 0000000000..c9ffebb202
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1076.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <root id="1">
+ <elem1 id="2">cat</elem1>
+ <elem1 id="3"> dog </elem1>
+ <elem1 id="4">
+ cat
+ <elem2 id="5">
+ <elem3 id="6">cat</elem3>
+ </elem2>
+ dog
+ </elem1>
+ <elem1 id="7">Cat</elem1>
+ </root>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/e1077.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1077.xml
new file mode 100644
index 0000000000..9aa548e13c
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1077.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE root [ <!ELEMENT e (e*) >
+ <!ATTLIST e id ID #REQUIRED>
+ ]>
+ <root>
+ <e id="1">
+ <e id="two">
+ <e id="3"/>
+ <e id="4">
+ <e id="the fifth"/>
+ </e>
+ <e id="6"/>
+ </e>
+ </e>
+ <e id="seven"/>
+ </root>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/e1078.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1078.xml
new file mode 100644
index 0000000000..a90db50145
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/e1078.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <root id="1">
+ <elem1 id="2" pet="cat"/>
+ <elem1 id="3" pet=" dog " age="8"/>
+ <elem1 id="4" pet="Cat" >
+ <elem2 id="5">
+ <elem3 id="6" age="10"/>
+ </elem2>
+ </elem1>
+ <elem1 id="7" pet="dog"/>
+ </root>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/motorcycles.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/motorcycles.xml
new file mode 100644
index 0000000000..b3629dce34
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/motorcycles.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<motorcycles>
+ <bike year="2000" color="black">
+ <name>
+ <manufacturer>Suzuki</manufacturer>
+ <brandName>Suzuki VL 1500</brandName>
+ <additionalName>Intruder</additionalName>
+ </name>
+ <engine>V-engine, 2-cylinders, 1500 cc</engine>
+ <kind>custom</kind>
+ <drive>cardan</drive>
+ <accessories>Sissy bar, luggage carrier,V&amp;H exhaust pipes</accessories>
+ </bike>
+ <date>2004.08.25</date>
+ <bike year="1983" color="read pearl">
+ <name>
+ <manufacturer>Yamaha</manufacturer>
+ <brandName>XJ 400</brandName>
+ </name>
+ <engine>4 cylinder, 400 cc</engine>
+ <kind>alround</kind>
+ <drive>chain</drive>
+ <comment>Good shape!</comment>
+ </bike>
+</motorcycles>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/myBS_model.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/myBS_model.xml
new file mode 100644
index 0000000000..58f90662a4
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/myBS_model.xml
@@ -0,0 +1,6 @@
+<myBS_model>
+
+ <blipp id="name1"/>
+ <blipp id="name2"/>
+
+</myBS_model>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/purchaseOrder.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/purchaseOrder.xml
new file mode 100644
index 0000000000..a5ae223d65
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/purchaseOrder.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<apo:purchaseOrder xmlns:apo="http://www.example.com/PO1"
+ orderDate="1999-10-20">
+ <billTo country="US">
+ <name>Robert Smith</name>
+ <street>8 Oak Avenue</street>
+ <!-- etc. -->
+ <city>Old Town</city>
+ <state>PA</state>
+ <zip>95819</zip>
+ </billTo>
+ <apo:comment>Hurry, my lawn is going wild!</apo:comment>
+ <shipTo country="US">
+ <name>Alice Smith</name>
+ <street>123 Maple Street</street>
+ <!-- etc. -->
+ <city>Mill Valley</city>
+ <state>CA</state>
+ <zip>90952</zip>
+ </shipTo>
+ <!-- etc. -->
+ <items>
+ <item partNum="872-AA">
+ <productName>Lawnmower</productName>
+ <quantity>1</quantity>
+ <USPrice>148.95</USPrice>
+ <comment>Confirm this is electric</comment>
+ </item>
+ <item partNum="926-AA">
+ <productName>Baby Monitor</productName>
+ <quantity>1</quantity>
+ <USPrice>39.98</USPrice>
+ <shipDate>1999-05-21</shipDate>
+ </item>
+ </items>
+</apo:purchaseOrder>
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath.xml b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath.xml
new file mode 100644
index 0000000000..248fbd413d
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath.xml
@@ -0,0 +1,25 @@
+<myBS_model>
+
+ <blipp id="name1">
+ <blupp att="bluppa"/>
+ </blipp>
+ <blipp id="name2">
+ <blupp att2="bluppb">
+ <plopp name="pl">here are some text</plopp>
+ </blupp>
+ </blipp>
+ <blipp id="name3" test="test1">
+ <blupp att2="bluppc">
+ <plopp name="plp">here are some more text</plopp>
+ </blupp>
+ <blupp att="bluppc2"/>
+ </blipp>
+
+ <blipp2 bid="name1">
+ <blupp att="bluppa"/>
+ <blupp att2="bluppb">
+ <plopp name="pl">here are some additional text</plopp>
+ </blupp>
+ </blipp2>
+
+</myBS_model> \ No newline at end of file
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_abbrev.erl b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_abbrev.erl
new file mode 100644
index 0000000000..850b7f8135
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_abbrev.erl
@@ -0,0 +1,266 @@
+%%%-------------------------------------------------------------------
+%%% File : xpath_abbrev.erl
+%%% Author : Bertil Karlsson <bertil@finrod>
+%%% Description :
+%%%
+%%% Created : 17 Jan 2006 by Bertil Karlsson <bertil@finrod>
+%%%-------------------------------------------------------------------
+-module(xpath_abbrev).
+
+-export([test/0, check_node_set/2, ticket_6873/0, ticket_7496/0, functions/0]).
+
+-include("test_server.hrl").
+-include_lib("xmerl/include/xmerl.hrl").
+
+test() ->
+ ?line {E,_} = xmerl_scan:file("xpath.xml"),
+
+ ?line Res1 = xmerl_xpath:string("blipp",E),
+ ?line ok = check_node_set("blipp",Res1),
+ ?line Res2 = xmerl_xpath:string("*",E),
+ ?line ok = check_node_set("*",Res2),
+ ?line Res3 = xmerl_xpath:string("blipp/blupp/plopp/text()",E),
+ ?line ok = check_node_set("blipp/blupp/plopp/text()",Res3),
+ ?line Res4 = xmerl_xpath:string("blipp/blupp/@att2",E),
+ ?line ok = check_node_set("blipp/blupp/@att2",Res4),
+ ?line Res5 = xmerl_xpath:string("blipp/@*",E),
+ ?line ok = check_node_set("blipp/@*",Res5),
+ ?line Res6 = xmerl_xpath:string("blipp[2]",E),
+ ?line ok = check_node_set("blipp[2]",Res6),
+ ?line Res7 = xmerl_xpath:string("blipp[last()]",E),
+ ?line ok = check_node_set("blipp[last()]",Res7),
+ ?line Res8 = xmerl_xpath:string("*/blupp",E),
+ ?line ok = check_node_set("*/blupp",Res8),
+ ?line Res9 = xmerl_xpath:string("/myBS_model/blipp[3]/blupp[2]",E),
+ ?line ok = check_node_set("/myBS_model/blipp[3]/blupp[2]",Res9),
+ ?line Res10 = xmerl_xpath:string("blipp//plopp",E),
+ ?line ok = check_node_set("blipp//plopp",Res10),
+ ?line Res11 = xmerl_xpath:string("//plopp",E),
+ ?line ok = check_node_set("//plopp",Res11),
+ ?line Res12 = xmerl_xpath:string("//blupp/plopp",E),
+ ?line ok = check_node_set("//blupp/plopp",Res12),
+ ?line Res13 = xmerl_xpath:string(".",E),
+ ?line ok = check_node_set(".",Res13),
+ ?line Res14 = xmerl_xpath:string(".//blipp2",E),
+ ?line ok = check_node_set(".//blipp2",Res14),
+ ?line Res15 = xmerl_xpath:string(".//blipp2/blupp/plopp/..",E),
+ ?line ok = check_node_set(".//blipp2/blupp/plopp/..",Res15),
+ ?line Res16 = xmerl_xpath:string(".//blipp[2]/blupp/plopp/../@att2",E),
+ ?line ok = check_node_set(".//blipp[2]/blupp/plopp/../@att2",Res16),
+ ?line Res17 = xmerl_xpath:string(".//blipp/blupp/plopp[2]/../@att2",E),
+ ?line ok = check_node_set(".//blipp/blupp/plopp[2]/../@att2",Res17),
+ ?line Res18 = xmerl_xpath:string("blipp[@id='name2']",E),
+ ?line ok = check_node_set("blipp[@id='name2']",Res18),
+ ?line Res19 = xmerl_xpath:string("blipp[@id='name2'][3]",E),
+ ?line ok = check_node_set("blipp[@id='name2'][3]",Res19),
+ ?line Res20 = xmerl_xpath:string("//blupp[plopp=\"here are some more text\"]",E),
+ ?line ok = check_node_set("//blupp[plopp=\"here are some more text\"]",Res20),
+ ?line Res21 = xmerl_xpath:string("//blupp[plopp]",E),
+ ?line ok = check_node_set("//blupp[plopp]",Res21),
+ ?line Res22 = xmerl_xpath:string("blipp[@id and @test]",E),
+ ?line ok = check_node_set("blipp[@id and @test]",Res22).
+
+check_node_set("blipp",[E1,E2,E3]) ->
+ ?line ok = xml_element_name(E1,blipp),
+ ?line ok = xml_element_name(E2,blipp),
+ ?line ok = xml_element_name(E3,blipp),
+ ok;
+check_node_set("*",[E1,E2,E3,E4]) ->
+ ?line ok = xml_element_name(E1,blipp),
+ ?line ok = xml_element_name(E2,blipp),
+ ?line ok = xml_element_name(E3,blipp),
+ ?line ok = xml_element_name(E4,blipp2),
+ ok;
+check_node_set("blipp/blupp/plopp/text()",[T1,T2]) ->
+ ?line #xmlText{value="here are some text"} = T1,
+ ?line #xmlText{value="here are some more text"} = T2,
+ ok;
+check_node_set("blipp/blupp/@att2",[A1,A2]) ->
+ ?line #xmlAttribute{name=att2} = A1,
+ ?line #xmlAttribute{name=att2} = A2,
+ ok;
+check_node_set("blipp/@*",[A1,A2,A3,A4]) ->
+ ?line #xmlAttribute{} = A1,
+ ?line #xmlAttribute{} = A2,
+ ?line #xmlAttribute{} = A3,
+ ?line #xmlAttribute{} = A4,
+ ok;
+check_node_set("blipp[2]",[E]) ->
+ ?line #xmlElement{name=blipp,
+ attributes=[#xmlAttribute{name=id,value="name2"}]} = E,
+ ok;
+check_node_set("blipp[last()]",[E]) ->
+ ?line #xmlElement{name=blipp,
+ attributes=[#xmlAttribute{name=id,value="name3"}|_]} = E,
+ ok;
+check_node_set("*/blupp",[E1,E2,E3,E4,E5,E6]) ->
+ ?line ok = xml_element_name(E1,blupp),
+ ?line ok = xml_element_name(E2,blupp),
+ ?line ok = xml_element_name(E3,blupp),
+ ?line ok = xml_element_name(E4,blupp),
+ ?line ok = xml_element_name(E5,blupp),
+ ?line ok = xml_element_name(E6,blupp),
+ ok;
+check_node_set("/myBS_model/blipp[3]/blupp[2]",[E]) ->
+ ?line #xmlElement{name=blupp,
+ attributes=[#xmlAttribute{name=att,value="bluppc2"}]}=E,
+ ok;
+check_node_set("blipp//plopp",[#xmlElement{name=plopp},#xmlElement{name=plopp}]) ->
+ ok;
+check_node_set("//plopp",[E1,E2,E3]) ->
+ ?line ok = xml_element_name(E1,plopp),
+ ?line ok = xml_element_name(E2,plopp),
+ ?line ok = xml_element_name(E3,plopp),
+ ok;
+check_node_set("//blupp/plopp",[E1,E2,E3]) ->
+ ?line ok = xml_element_name(E1,plopp),
+ ?line ok = xml_element_name(E2,plopp),
+ ?line ok = xml_element_name(E3,plopp),
+ ok;
+check_node_set(".",[#xmlElement{name=myBS_model}]) ->
+ ok;
+check_node_set(".//blipp2",[#xmlElement{name=blipp2}]) ->
+ ok;
+check_node_set(".//blipp2/blupp/plopp/..",[#xmlElement{name=blupp}]) ->
+ ok;
+check_node_set(".//blipp[2]/blupp/plopp/../@att2",[#xmlAttribute{name=att2,value="bluppb"}]) ->
+ ok;
+check_node_set(".//blipp/blupp/plopp[2]/../@att2",[#xmlAttribute{name=att2,value="bluppc"}]) ->
+ ok;
+check_node_set("blipp[@id='name2']",[E]) ->
+ ?line #xmlElement{name=blipp,
+ attributes=[#xmlAttribute{name=id,value="name2"}]}=E,
+ ok;
+check_node_set("blipp[@id='name2'][3]",[]) ->
+ ok;
+check_node_set("//blupp[plopp=\"here are some more text\"]",[E]) ->
+ ?line #xmlElement{name=blupp,
+ content=[_T,#xmlElement{name=plopp,content=C}|_]} = E,
+ ?line true = lists:keymember("here are some more text",#xmlText.value,C),
+ ok;
+check_node_set("//blupp[plopp]",[E1,E2,E3]) ->
+ ?line #xmlElement{name=blupp,
+ content=C1} = E1,
+ ?line true = lists:keymember(plopp,#xmlElement.name,C1),
+ ?line #xmlElement{name=blupp,
+ content=C2} = E2,
+ ?line true = lists:keymember(plopp,#xmlElement.name,C2),
+ ?line #xmlElement{name=blupp,
+ content=C3} = E3,
+ ?line true = lists:keymember(plopp,#xmlElement.name,C3),
+ ok;
+check_node_set("blipp[@id and @test]",[E]) ->
+ ?line #xmlElement{name=blipp,
+ attributes=Atts} = E,
+ ?line true = lists:keymember(id,#xmlAttribute.name,Atts),
+ ?line true = lists:keymember(test,#xmlAttribute.name,Atts),
+ ok;
+check_node_set(Pattern,NodeSet) ->
+ io:format("Pattern: ~p~nNodeSet: ~p~n",[Pattern,NodeSet]),
+ error.
+
+xml_element_name(E,N) ->
+ ?line #xmlElement{name=N} = E,
+ ok.
+
+ticket_6873() ->
+ ?line [#xmlElement{}] = xmerl_xpath:string("//foo[contains(@bar, 'oe')]",element(1,xmerl_scan:string("<foo bar=\"Joe\" />"))),
+ ok.
+
+ticket_7496() ->
+ Test = fun(Doc, XPath, Exp) ->
+ Result = xmerl_xpath:string(XPath, Doc),
+ ?line Exp = [Name || #xmlElement{name = Name} <- Result],
+ ok
+ end,
+ ?line {Doc1,_} = xmerl_scan:string("<a><b/> <c/> <d/> <e/></a>"),
+ ?line ok = Test(Doc1, "//b/following::*", [c, d, e]),
+ ?line ok = Test(Doc1,"//b/following::*[1]", [c]),
+ ?line ok = Test(Doc1,"//b/following::*[position()=1]", [c]),
+ ?line ok = Test(Doc1,"//b/following::*[3]", [e]),
+ ?line ok = Test(Doc1,"//b/following::*[position()=3]", [e]),
+ ?line ok = Test(Doc1,"//e/preceding::*", [b, c, d]),
+ ?line ok = Test(Doc1,"//e/preceding::*[1]", [d]),
+ ?line ok = Test(Doc1,"//e/preceding::*[position()=1]", [d]),
+ ?line ok = Test(Doc1,"//e/preceding::*[3]", [b]),
+ ?line ok = Test(Doc1,"//e/preceding::*[position()=3]", [b]),
+ ?line ok = Test(Doc1,"//b/following::*[position() mod 2=0]", [d]),
+ ?line ok = Test(Doc1,"//b/self::*", [b]),
+
+ ?line {Doc2,_} = xmerl_scan:string("<a><b/> <c><d/></c> <e/> <f><g/></f> <h/> <i><j/></i> <k/></a>"),
+ ?line ok = Test(Doc2,"//g/preceding::*", [b, c, d, e]),
+ ?line ok = Test(Doc2, "//g/following::*", [h, i, j, k]),
+ ?line ok = Test(Doc2,"//g/ancestor::*", [a, f]),
+ ?line ok = Test(Doc2,"//g/ancestor::*[1]", [f]),
+ ?line ok = Test(Doc2,"//g/ancestor::*[2]", [a]),
+ ?line ok = Test(Doc2,"//g/ancestor-or-self::*", [a, f, g]),
+ ?line ok = Test(Doc2,"//g/ancestor-or-self::*[1]", [g]),
+ ?line ok = Test(Doc2,"//g/ancestor-or-self::*[2]", [f]),
+ ?line ok = Test(Doc2,"//g/ancestor-or-self::*[3]", [a]),
+ ?line ok = Test(Doc2,"/descendant::*", [a, b, c, d, e, f, g, h, i, j, k]),
+ ?line ok = Test(Doc2,"//f/preceding-sibling::*", [b, c, e]),
+ ?line ok = Test(Doc2,"//f/following-sibling::*", [h, i, k]),
+ ?line ok = Test(Doc2,"//f/self::*", [f]),
+ ?line ok = Test(Doc2,"//f/ancestor::*", [a]),
+ ?line ok = Test(Doc2,"//f/descendant::*", [g]),
+ ?line ok = Test(Doc2,"//f/preceding::*", [b, c, d, e]),
+ ?line ok = Test(Doc2,"//f/following::*", [h, i, j, k]),
+ ?line ok = Test(Doc2,"//text()[1]/following-sibling::*", [c, e, f, h, i, k]),
+
+ ?line {Doc3,_} = xmerl_scan:file("documentRoot.xml"),
+ ?line ok = Test(Doc3,"//child",[child,child,child]),
+ ?line ok = Test(Doc3,"//child[@name='beta']",[child]),
+ ?line [{xmlAttribute,id,[],[],[],[],1,[],"2",false}] =
+ xmerl_xpath:string("/documentRoot/parent/child[@name='beta']/@id",Doc3),
+ ?line ok = Test(Doc3,"/documentRoot/parent/child|/documentRoot/parent/pet",
+ [child,child,child,pet,pet]),
+ ?line ok = Test(Doc3,"//*[starts-with(local-name(),'p')]",
+ [parent,pet,pet]).
+
+
+functions() ->
+ Test = fun(Doc, XPath, Exp) ->
+ Result = xmerl_xpath:string(XPath, Doc),
+ ?line Exp = [begin
+ case Obj of
+ #xmlElement{name = EName} ->
+ EName;
+ #xmlAttribute{name = AName} ->
+ AName;
+ #xmlText{value=Text} ->
+ Text
+ end
+ end|| Obj <- Result],
+ ok
+ end,
+ Foo =
+ "<foo>"
+ " <bar>"
+ " <name>Xml</name>"
+ " <value>1</value>"
+ " </bar>"
+ " <bar>"
+ " <name>Xpath</name>"
+ " <value>2</value>"
+ " </bar>"
+ " <bar>"
+ " <name>Erlang</name>"
+ " <value>3</value>"
+ " </bar>"
+ "</foo>",
+ {Doc,_} = xmerl_scan:string(Foo),
+ ?line ok = Test(Doc,"/foo/bar[name = 'Xml']/value/text()",["1"]),
+ ?line ok = Test(Doc,"/foo/bar/node()/text()",
+ ["Xml","1","Xpath","2","Erlang","3"]),
+ ?line ok = Test(Doc,"/foo/bar[contains(name, 'path')]",[bar]),
+ ?line ok = Test(Doc,"/foo/bar[starts-with(name, 'X')]",[bar,bar]),
+ ?line ok = Test(Doc,"/foo/bar[value = string(1)]/value/text()",["1"]),
+
+
+ {Doc2,_}= xmerl_scan:file("purchaseOrder.xml"),
+ ?line ok = Test(Doc2,"//*[starts-with(local-name(),'c')]",
+ ['apo:comment',city,city,comment]),
+ ?line ok = Test(Doc2,"//*[starts-with(name(),'c')]",
+ [city,city,comment]),
+ ?line ok = Test(Doc2,"//*[starts-with(name(),'{http://www.example.com/PO1')]",
+ ['apo:purchaseOrder','apo:comment']).
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_lib.erl b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_lib.erl
new file mode 100644
index 0000000000..4cde46826e
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_lib.erl
@@ -0,0 +1,184 @@
+%%%-------------------------------------------------------------------
+%%% File : xpath_lib.erl
+%%% Author : Bertil Karlsson <bertil@finrod>
+%%% Description :
+%%%
+%%% Created : 13 Jan 2006 by Bertil Karlsson <bertil@finrod>
+%%%-------------------------------------------------------------------
+-module(xpath_lib).
+
+-export([test/0,check_node_set/2,ticket_6873/0]).
+
+-include("test_server.hrl").
+-include_lib("xmerl/include/xmerl.hrl").
+
+test() ->
+ ?line {E,_} = xmerl_scan:file("myBS_model.xml"),
+ ?line Res1 = xmerl_xpath:string("blipp",E),
+ ?line ok = check_node_set("blipp",Res1),
+ ?line Res2 = xmerl_xpath:string("//blipp",E),
+ ?line ok = check_node_set("//blipp",Res2),
+ ?line Res3 = xmerl_xpath:string("/myBS_model/blipp",E),
+ ?line ok = check_node_set("/myBS_model/blipp",Res3),
+ ?line Res4 = xmerl_xpath:string("blipp[@id=\"name1\"]",E),
+ ?line ok = check_node_set("blipp[@id=\"name1\"]",Res4),
+ ?line Res5 = xmerl_xpath:string("//blipp[@id=\"name1\"]",E),
+ ?line ok = check_node_set("//blipp[@id=\"name1\"]",Res5),
+ ?line Res6 = xmerl_xpath:string("/myBS_model/blipp[@id=\"name1\"]",E),
+ ?line ok = check_node_set("/myBS_model/blipp[@id=\"name1\"]",Res6).
+
+
+check_node_set("blipp",[H1,H2]) ->
+ ?line #xmlElement{name = blipp} = H1,
+ ?line #xmlElement{name = blipp} = H2,
+ ok;
+check_node_set("//blipp",[H1,H2]) ->
+ ?line #xmlElement{name = blipp} = H1,
+ ?line #xmlElement{name = blipp} = H2,
+ ok;
+check_node_set("/myBS_model/blipp",[H1,H2]) ->
+ ?line #xmlElement{name = blipp} = H1,
+ ?line #xmlElement{name = blipp} = H2,
+ ok;
+check_node_set("blipp[@id=\"name1\"]",[H]) ->
+ ?line H#xmlElement{attributes=#xmlAttribute{name=id,value="name1"}},
+ ok;
+check_node_set("//blipp[@id=\"name1\"]",[H]) ->
+ ?line H#xmlElement{attributes=#xmlAttribute{name=id,value="name1"}},
+ ok;
+check_node_set("/myBS_model/blipp[@id=\"name1\"]",[H]) ->
+ ?line H#xmlElement{attributes=#xmlAttribute{name=id,value="name1"}},
+ ok.
+
+ticket_6873() ->
+ GetId =
+ fun(Atts) ->
+ case lists:keysearch(id,#xmlAttribute.name,Atts) of
+ {value,#xmlAttribute{value=AttV}} -> AttV;
+ _ -> novalue
+ end
+ end,
+ Test =
+ fun(Doc, XPath, Exp) ->
+ Result = xmerl_xpath:string(XPath, Doc),
+ Exp = [begin
+ case Obj of
+ #xmlElement{name = EName,attributes=Atts} ->
+ {EName,GetId(Atts)};
+ #xmlAttribute{name = AName} ->
+ AName;
+ #xmlText{value=Text} ->
+ Text
+ end
+ end|| Obj <- Result],
+ ok
+ end,
+
+
+
+ Doc1 = get_doc("e1074"),
+ ?line ok = Test(Doc1,"/*",[{root,"1"}]),
+ ?line ok = Test(Doc1,"/root",[{root,"1"}]),
+ ?line ok = Test(Doc1,"/root/*",[{elem1,"2"},{elem1,"8"},{e,"12"}]),
+ ?line ok = Test(Doc1,"/root/e",[{e,"12"}]),
+ ?line ok = Test(Doc1,"//e",[{e,"12"},{e,"4"},{e,"6"},{e,"10"},{e,"11"}]),
+ ?line ok = Test(Doc1,"//*[name() != 'e']",
+ [{root,"1"},{elem1,"2"},{elem1,"8"},{elem2,"3"},
+ {elem3,"5"},{elem3,"7"},{elem2,"9"}]),
+ ?line ok = Test(Doc1,"//elem1/e",[{e,"10"},{e,"11"}]),
+ ?line ok = Test(Doc1,"//elem1//e",[{e,"4"},{e,"6"},{e,"10"},{e,"11"}]),
+ ?line ok = Test(Doc1,"//*[*]",
+ [{root,"1"},{elem1,"2"},{elem1,"8"},
+ {elem2,"3"},{elem3,"5"}]),
+ ?line ok = Test(Doc1,"//*[not(*)]",
+ [{e,"12"},{e,"4"},{elem3,"7"},{e,"6"},
+ {elem2,"9"},{e,"10"},{e,"11"}]),
+ %% contents would be empty in the above expression
+ ?line [#xmlElement{content=[]}|_] = xmerl_xpath:string("//*[not(*)]",Doc1),
+ ?line ok = Test(Doc1,"//*[e]",[{root,"1"},{elem1,"8"},{elem2,"3"},{elem3,"5"}]),
+ ?line ok = Test(Doc1,"//*[count(e)>1]",[{elem1,"8"}]),
+ ?line ok = Test(Doc1,"//*[not(e) and name() != 'e']",
+ [{elem1,"2"},{elem3,"7"},{elem2,"9"}]),
+ ?line ok = Test(Doc1,"/*/*/*/e",[{e,"4"}]),
+ ?line ok = Test(Doc1,"//*[starts-with(name(), 'el')]",
+ [{elem1,"2"},{elem1,"8"},{elem2,"3"},
+ {elem3,"5"},{elem3,"7"},{elem2,"9"}]),
+ ?line ok = Test(Doc1,"//*[contains(name(), 'lem1')]",
+ [{elem1,"2"},{elem1,"8"}]),
+ ?line ok = Test(Doc1,"/*/e | //elem2/e",[{e,"4"},{e,"12"}]),
+
+ io:format("Tested ~p~n",[e1074]),
+
+ Doc2 = get_doc("e1075"),
+ ?line ok = Test(Doc2,"/*/*[1]",[{elem1,"2"}]),
+ ?line ok = Test(Doc2,"/root/elem1[2]",[{elem1,"8"}]),
+
+ %% Get all first-born e elements in the document; that is, for all
+ %% e elements with e element siblings, include only the first
+ %% sibling.Note that //e[1] does not return the first e element in
+ %% the document because the [1] predicate applies to e, which
+ %% represents the set of e elements under one element and not to
+ %% //e, which represents the set of e elements in the document.
+ %% ?line ok = Test(Doc2,"//e[1]",[{e,"4"},{e,"6"},{e,"10"},{e,"12"}]),
+
+ %% The following expression retrieves the first e element in the
+ %% document:
+ %% ?line ok = Test(Doc2,"(//e)[1]",[{e,4}]),
+
+ %% For all e elements with e element siblings, include only the
+ %% first 3 siblings
+ %% ?line ok = Test(Doc2,"//e[position() <= 3]",[{e,"4"},{e,"6"},{e,"10"},{e,"11"},{e,"12"}]),
+
+ %% Get all last-born e elements in the document; that is, for all
+ %% e elements with e element siblings, include only the last
+ %% sibling
+ %% ?line ok = Test(Doc2,"//e[last()]",[{e,"4"},{e,"6"},{e,"11"},{e,"12"}]),
+
+ %% Get the last e element in the document
+ %% ?line ok = Test(Doc2,"(//e)[last()]", [{e,"12"}]),
+
+
+ io:format("Tested ~p~n",[e1075]),
+
+
+ Doc3 = get_doc("e1076"),
+ ?line ok = Test(Doc3,"//*[.='cat']",[{elem1,"2"},{elem3,"6"}]),
+ ?line ok = Test(Doc3,"//*[.='dog']",[]),
+ ?line ok = Test(Doc3,"//*[contains(.,'cat')]",
+ [{elem1,"2"},{elem1,"4"},{elem3,"6"}]),
+ ?line ok = Test(Doc3,"//elem3[contains(.,'cat')]",[{elem3,"6"}]),
+ ?line ok = Test(Doc3,"//*[contains(child::text(),'cat')]",[{elem1,"2"},{elem1,"4"},{elem3,"6"}]),
+ ?line ok = Test(Doc3,"//*[count(*)=0 and contains(.,'cat')]",[{elem1,"2"},{elem3,"6"}]),
+ ?line ok = Test(Doc3,"//*[contains(translate(.,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'CAT')]",[{elem1,"2"},{elem1,"4"},{elem1,"7"},{elem3,"6"}]),
+
+ io:format("Tested ~p~n",[e1076]),
+
+ Doc4 = get_doc("e1078"),
+ ?line ok = Test(Doc4,"//*[@pet='cat']",[{elem1,"2"}]),
+ ?line ok = Test(Doc4,"//*[@pet='dog']",[{elem1,"7"}]),
+ ?line ok = Test(Doc4,"//*[contains(@pet,'dog')]",
+ [{elem1,"3"},{elem1,"7"}]),
+ ?line ok = Test(Doc4,"//*[@age]",[{elem1,"3"},{elem3,"6"}]),
+ ?line ok = Test(Doc4,"//elem1[@age]",[{elem1,"3"}]),
+ ?line ok = Test(Doc4,"//*[@pet and @age]",[{elem1,"3"}]),
+ ?line ok = Test(Doc4,"//*[contains(translate(@pet,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'CAT')]",[{elem1,"2"},{elem1,"4"}]),
+
+ io:format("Tested ~p~n",[e1078]),
+
+
+ Doc5 = get_doc("e1077"),
+ ?line ok = Test(Doc5,"id('3')",[{e,"3"}]),
+
+ %% Get all e elements directly under element id 3
+ %% ?line ok = Test(Doc5,"id('two')/e",[{e,"3"},{e,"4"},{e,"6"}]),
+ ?line ok = Test(Doc5,"id('two 3 seven the fifth')",[{e,"seven"},{e,"3"},{e,"two"}]),
+ ?line ok = Test(Doc5,"id('100')",[]),
+
+ io:format("Tested ~p~n",[e1077]),
+ ok.
+
+
+
+get_doc(Name) ->
+ ?line {Doc,_} = xmerl_scan:file(Name++".xml"),
+ Doc.
diff --git a/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_text.erl b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_text.erl
new file mode 100644
index 0000000000..e39ad6bcb0
--- /dev/null
+++ b/lib/xmerl/test/xmerl_SUITE_data/xpath/xpath_text.erl
@@ -0,0 +1,28 @@
+%%%-------------------------------------------------------------------
+%%% File : xpath_text.erl
+%%% Author : Bertil Karlsson <bertil@finrod>
+%%% Description :
+%%%
+%%% Created : 14 Dec 2004 by Bertil Karlsson <bertil@finrod>
+%%%-------------------------------------------------------------------
+-module(xpath_text).
+
+-compile(export_all).
+
+-include("test_server.hrl").
+-include_lib("xmerl/include/xmerl.hrl").
+
+-import(xmerl_xs,
+ [ xslapply/2, value_of/1, select/2, built_in_rules/2 ]).
+
+
+one() ->
+ ?line {A,_}=xmerl_scan:file('motorcycles.xml'),
+ ?line [["Suzuki","Yamaha"]] = template(A),
+ ok.
+
+%%% templates, test of OTP-5268
+template(E = #xmlElement{name='motorcycles'}) ->
+ [value_of(select("bike/name/manufacturer/text()",E))];
+template(E) -> built_in_rules(fun template/1, E).
+