我有一个XML文档,如下所示。我正在尝试获取所有元素和属性的键/值对。我的查询获取所有元素名称和元素值。但是,我想获取属性名称和属性值(最好是在同一个查询中,否则在不同的查询中)。
XML文档:
function read_hashes(){
try { // I know I shouldn't use try... but this is a easy way to reject invalid hashes
var hashes = window.location.hash;
hashes = hashes.substring(1);
hashes = JSON.parse(decodeURIComponent(hashes));
if (hashes["user_dat1"] != null){//check if var is in json hash
//do what you need to do with this var.
}
...
} catch(err){}
}
function put_hashes(){
var hashes = {};
hashes["user_dat1"] = "test data";
hashes = encodeURIComponent(JSON.stringify(hashes));
window.location.hash ="#" + hashes;
}
Oracle中的SQL查询:
<bookstore>
<book category="COOKING">
<title lang="en">Cook Book</title>
<author>Chef Author</author>
<year>2015</year>
<price>310.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Kid Story Book</title>
<author>KJ Banter</author>
<year>2010</year>
<price>229.99</price>
</book>
</bookstore>
答案 0 :(得分:1)
鉴于您希望它们按文档顺序排列,请为每个检索到的元素下降并遵循其自身和属性轴。您需要以不同方式检索元素和属性值,因此应用ancestor-or-self
:
ancestor
另请注意,我已将$node
步骤更改为ancestor
步骤并明确返回In [24]: def m1():
....: return "I am legend"
....:
In [25]: f1 = m1
In [26]: type(f1)
Out[26]: function
In [27]: type(m1)
Out[27]: function
的名称,因此我们不必区分元素和属性再次出现在def m1() = "I am legend"
轴上。