How to unencode escaped XML with xQuery

前端 未结 3 458
-上瘾入骨i
-上瘾入骨i 2021-01-17 23:16

I have a variable in xQuery of type xs:string with the value of an encoded HTML snippet (the content of a twitter tweet). It looks like this:

Headline

相关标签:
3条回答
  • 2021-01-17 23:23

    In MarkLogic you can use the below query:

    let $d := '<a>&lt;c&gt;asdf&lt;/c&gt;</a>' 
    
    return xdmp:unquote ($d)
    
    0 讨论(0)
  • 2021-01-17 23:31

    in eXist, use util:parse():

    util:parse(concat("<top>","&lt;c&gt;asdf&lt;/c&gt;",</top>")‌​)
    
    0 讨论(0)
  • 2021-01-17 23:38

    Depends on which XQuery processor you are using... The easiest way is to be using a processor that has an extension that handles this for you. For instance, with Saxon and the following XML:

    <a>&lt;c&gt;asdf&lt;/c&gt;</a>
    

    You can write an XQuery that uses the saxon:parse() function to do what you want:

    declare namespace saxon = "http://saxon.sf.net/";
    
    <a>{
      saxon:parse(doc('test.xml')/a)
    }</a>
    

    The result from that is:

    <a>
      <c>asdf</c>
    </a>
    

    I think most(?) XQuery processors will have an extension to do this for you. Hope that helps.

    0 讨论(0)
提交回复
热议问题