我正在尝试构建简单的XML数据库(在BaseX或eXist-db中),但我无法确定如何修改文档中的值:
内容很简单,因为测试:
<p>
<pl>
<id>6></id>
</pl>
</p>
Run Code Online (Sandbox Code Playgroud)
我正在尝试构建类似函数的东西,<pl>如果元素不存在则会插入元素,如果存在则替换它.但XQuery给了我麻烦:
当我尝试使用if-then-else逻辑时:
if (exists(/p/pl[id=6]/name)=false)
then insert node <name>thenname</name> into /p/pl[id=6]
else replace value of node /p/pl[id=6]/name with 'elsename'
Run Code Online (Sandbox Code Playgroud)
我收到错误Error: [XUDY0027] Replace target must not be empty.显然我很困惑,为什么在两种情况下评估else部分,因此错误.当我清空其他部分时:
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
Run Code Online (Sandbox Code Playgroud)
然后我明白了Error: [XUST0001] If expression: no updating expression allowed.
当我尝试声明更新功能时,即使它报告错误:
declare namespace testa='test';
declare updating function testa:bid($a, $b)
{
if (exists(/p/pl[id=6]/name)=true)
then insert node <name>thenname</name> into /p/pl[id=6]
else <dummy/>
};
testa:bid(0,0)
Run Code Online (Sandbox Code Playgroud)
Error: …
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Run Code Online (Sandbox Code Playgroud)
xmlstarlet sel -t -v"// @ category"books.xml
仅返回COOKING.如何获取所有属性命名类别?
奖励问题:我如何评估XML文件的XPath查询,而无需在编辑器或程序中打开它(我想要一个快速工具).问题是将大文件加载到内存会导致编辑器崩溃.不要告诉我eXist是我最好的选择吗?
我在eXist上写xquery .
通常我用这种方式在xml中选择项目:
fn:doc($document_name)/root/a
Run Code Online (Sandbox Code Playgroud)
但现在我想从字符串变量中获取xpath:
let $xpath := request:get-parameter("xpath", "")
fn:doc($document_name)/$xpath
Run Code Online (Sandbox Code Playgroud)
当然它不起作用.我现在找到的唯一方法是使用eval:
util:eval(fn:concat("fn:doc($document_name)", $xpath)):)
Run Code Online (Sandbox Code Playgroud)
但我不想使用,eval因为它很慢而且不安全.
我知道有类似的东西:
fn:doc($document_name)/*[name()='node_name']
Run Code Online (Sandbox Code Playgroud)
但我想通过整个路径选择项目,但不仅仅是节点的名称,我也尝试使用node-xpath()但不知道如何使用它就像name()
我在linux中运行eXist-db,但是我无法通过find命令等linux命令找到在文件系统中创建的XML文件.我怎样才能看到这些XML文件?
我有一个看起来像这样的数据库(访问它$database):
<country car_code="F" area="547030" capital="cty-france-paris">
<name>France</name>
<border country="AND" length="60"/>
<border country="E" length="623"/>
<border country="D" length="451"/>
<border country="I" length="488"/>
<border country="CH" length="573"/>
<border country="B" length="620"/>
<border country="L" length="73"/>
<border country="MC" length="4.4"/>
</country>
.....
other countries
Run Code Online (Sandbox Code Playgroud)
我想写一个函数,通过陆地边界提供从法国(或任何其他国家)可以到达的所有国家的名称.第一次尝试(可能有很多语法错误和其他错误,但程序的语义应该"更清楚"):
declare function local:reachable($country as element())
as (return value should be a sequence of countries )
{
if $country == () (:if empty, it doesn't border to any other country:)
then ()
else(
$country/name UNION (for $bord in $country/border/@country return
local:reachable ($database/country/car_code = @bord …Run Code Online (Sandbox Code Playgroud) $array = Array
(
[0] => Array
(
[id] => 46
[title] => sometext
)
[1] => Array
(
[id] => 47
[title] => sometext
)
[2] => Array
(
[id] => 48
[title] => sometext
)
[3] => Array
(
[id] => 49
[title] => sometext
)
[4] => Array
(
[id] => 50
[title] => sometext
)
)
Run Code Online (Sandbox Code Playgroud)
我们有一个数组和一个变量:
$variable = 48; //some number
Run Code Online (Sandbox Code Playgroud)
我们如何检查内部$variable某些数组中是否存在?['id']$array
回来true还是false.
如何检查XQuery存在方法中的多个值?我XQuery在SQL语句中运行它
Select [column1] [xmlcolumn] from tablet
where [xmlcolumn].exist('/node/subnode/subsubnode[.="value1"]') = 1
Run Code Online (Sandbox Code Playgroud)
我希望能够指定多个值like [.="value1" OR "value2" OR ...].
任何指针都表示赞赏.
我需要一个XQuery来删除任何不是{AZ,az,_,0-9}的字符 - 而不必在查询中明确指定它们.
目前我正在使用:
for $x in /xml/TEST
let $i := concat('M', replace($x/ID, '[\[\]\(\)°: ]', ''))
return element {$i} {$x/* except $x/ID}
Run Code Online (Sandbox Code Playgroud)
但每当一个新的非法角色爬上来时,我需要调整那个命令......所以:不完美.
有任何想法吗?
谢谢!
试着玩一些批处理.
@ echo off
IF EXIST %CD%\Minecraft.exe
Minecraft.exe
IF NOT exist %CD%\Minecraft.exe
wget.exe https://s3.amazonaws.com/MinecraftDownload/launcher/Minecraft.exe
Minecraft.exe
pause
Run Code Online (Sandbox Code Playgroud)
我做错了什么?当我运行它时,CMD就会关闭.
我需要批处理 file.bat 来做
我有 filename.txt 内容:
blah blah
....
Miss Phuong
I love you all. Miss Phuong
End of file
Run Code Online (Sandbox Code Playgroud)
如果该行不存在,我想在末尾插入以下行:
I love you all
Miss Phuong
Run Code Online (Sandbox Code Playgroud)
运行后是:
blah blah
....
Miss Phuong
I love you all. Miss Phuong
End of file
I love you all
Run Code Online (Sandbox Code Playgroud)
由于线路存在,“Miss Phuong”将不会被添加。将添加“我爱你们所有人”,因为存在字符串“我爱你们所有人”,但该行是“我爱你们所有人。Phuong 小姐”
谢谢
我正在尝试在symfony2(php app/console cache:clear --env-prod)上清理我的prod缓存,我收到以下错误:
[InvalidArgumentException]文件"/var/www/vhosts/ns21206.ovh.net/citydom/app/config/config_.yml"不存在.
在我的文件中,app.php我使用以下行创建了项目:
$kernel = new AppKernel('prod', true);
Run Code Online (Sandbox Code Playgroud)
我觉得这很标准.
我认为symfony试图用env""创建项目,但我不知道为什么.
我做错了什么 ?
任何人都可以告诉我什么是"元组"和"元组流"吗?这个XML文档中有多少个元组?我们如何列出本文档中的前三个元组?
<a>
<b>
<a/>
</b>
<c>
<b/>
</c>
</a>
Run Code Online (Sandbox Code Playgroud) 在我的程序中,用户完成一个表单然后按下Submit.然后,创建文本文件或随机扩展文件,其中写入所有用户的信息.因此,每当用户运行应用程序表单时,它将检查是否存在具有所有信息的文件,然后复制信息并将其粘贴到表单中.但是,它由于某种原因不起作用(没有语法错误):
procedure TForm1.FormCreate(Sender: TObject);
var
filedest: string;
f: TextFile;
info: array[1..12] of string;
begin
filedest := ExtractFilePath(ParamStr(0)) + 'User\Identity\IdentityofMyself.txt';
if FileExists(filedest) then
begin
AssignFile(f,filedest);
Reset(f);
ReadLn(info[1], info[2], info[3], info[4], info[5], info[6], info[7],
info[8], info[9], info[10], info[11], info[12]);
Edit1.Text := info[1];
Edit2.Text := info[2];
ComboBox1.Text := info[3];
ComboBox5.Text := info[4];
ComboBox8.Text := info[4];
ComboBox6.Text := info[5];
ComboBox7.Text := info[6];
Edit3.Text := info[7];
Edit4.Text := info[8];
Edit5.Text := info[11];
Edit6.Text := info[12];
ComboBox9.Text := info[9];
ComboBox10.Text := info[10];
CloseFile(f);
end …Run Code Online (Sandbox Code Playgroud)