使用 saxon xquery 从 xml 中删除元素 [英] removing an element from xml using saxon xquery

查看:43
本文介绍了使用 saxon xquery 从 xml 中删除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的 xml:

Hi I have an xml like this:

<ns1:books><ns2:book category="WEB"><ns3:title lang="en">Learning XML</ns3:title>
<ns3:author>Erik T. Ray</ns3:author><ns3:year>2003</ns3:year><ns3:price>39.95</price>

使用 Saxon xquery 我想删除 ns3:author 元素,谁能告诉我我该怎么做?

Using Saxon xquery I want to remove the ns3:author element, could anyone let me know how can I do it ?

我知道有一个 fn:remove(..) 方法,但我不想使用它,因为它需要一个整数作为第二个参数

I know there is a fn:remove(..) method but I don't want to use that as it takes an integer as a 2nd argument

任何完整的代码将不胜感激

Any complete code will be much appreciated

还有对于撒克逊人,我正面临像

Also with saxon I am facing the error like

Caused by: net.sf.saxon.trans.StaticError: #...nt-node() external中的XQuery语法错误;复制 $temp#:超出查询结束的意外标记$"

Caused by: net.sf.saxon.trans.StaticError: XQuery syntax error in #...nt-node() external; copy $temp#: Unexpected token "$" beyond end of query

我使用了 xml

声明命名空间soapenv="http://www.w3.org/2003/05/soap-envelope";声明命名空间 reg="http://www.mycompany.com/internal/xsd/registrationservice";声明命名空间 reg1="http://www.mycompany.com/internal/xsd/registrationtypes";

declare namespace soapenv="http://www.w3.org/2003/05/soap-envelope"; declare namespace reg="http://www.mycompany.com/internal/xsd/registrationservice"; declare namespace reg1="http://www.mycompany.com/internal/xsd/registrationtypes";

declare variable $RegistrationServiceRequest := <reg:RegistrationServiceRequest><reg1:RegistrationAttributes>       <reg1:Username>fdf</reg1:Username><reg1:Password>passwdfdford1</reg1:Password>      <reg1:Title>Mdfdfr</reg1:Title><reg1:FirstName>fdsfdsfsd</reg1:FirstName>
            </reg1:RegistrationAttributes><reg1:AutoLogin> <reg1:AutoLogin1>trtrtrt</reg1:AutoLogin1></reg1:AutoLogin>
        </reg:RegistrationServiceRequest>;
        copy $temp := $RegistrationServiceRequest 
modify delete node $temp/reg1:AutoLogin
return $temp

但是当我尝试使用 zorba 时,它工作正常,唯一的问题是撒克逊人,错误在于复制行

but when i tried with zorba it worked fine , the only problem is with the saxon and the error is at copy line

知道如何解决这个问题吗?

Any idea how to fix this ?

谢谢

推荐答案

如果您想对文档进行小的更改,XQuery 不是您的最佳选择.您可以使用 XQuery 更新来完成,也可以使用 XSLT 来完成.单独使用 XQuery 是可能的,但非常麻烦.

If you want to make a small change to a document, XQuery is not your best choice. You can do it with XQuery update, or you can do it with XSLT. Doing it with XQuery alone is possible, but very cumbersome.

这篇关于使用 saxon xquery 从 xml 中删除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆