我从 XML 中获取一些数据并将其转换为 Turtle/N3。我想在开头添加 @prefix 和命名空间 URL。原始 XML 类似于:
<xxx>
<country
name="XX"
population="NN">
...
</country>
...
</xxx>
我编写了 XQuery:
declare function local:genPopulation()as xs:string* {
let $countries:=doc("mondial-3.0.xml")//country
for $elt in $countries
let $population := $elt/@population[1]
let $countryName := $elt/@name
return (concat(":",$countryName,":population :",$population,".
"))
};
"
","@prefix rdf: <http://www.w3.org/1999/02/22‐rdf‐syntax‐ns#> .","
",
"@prefix : <http://lyle.smu.edu/cse7347/> .","
",
local:genPopulation()
输出是:
<?xml version="1.0" encoding="UTF-8"?>
@prefix rdf: <http://www.w3.org/1999/02/22‐rdf‐syntax‐ns#> .
@prefix : <http://lyle.smu.edu/cse7347/> .
:Albania:population :3249136.
:Andorra:population :72766.
..
...
输出将原始的“<”和“>”翻译成“<”和“>”。如何保持这些字符串不变?我想要这样的输出:
@prefix rdf: <http://www.w3.org/1999/02/22‐rdf‐syntax‐ns#> .
@prefix : <http://lyle.smu.edu/cse7347/> .
:Albania:population :3249136.
...