Parsing XML within string constructors

Saturday, 19 March 2016 · 2 messages · last reply 21 Mar 2016
TT
Tim Thompson19 Mar 2016 06:40 #
Hello, I have a string that I want to parse using fn:parse-xml-fragment (in BaseX 8.4.1). I noticed that there seemed to be a difference when wrapping the string in a string constructor versus plain quotes. Using the string constructor seems to require a second function call in order to parse the XML. The following three expressions illustrate the difference. Numbers 2 and 3 return parsed XML, whereas number 1 returns the original, unparsed string. Is this the expected behavior when using string constructors? 1. ``[<span start="" end="3">Sed</span> ut perspiciatis]`` => parse-xml-fragment() 2. ``[<span start="" end="3">Sed</span> ut perspiciatis]`` => parse-xml-fragment() => parse-xml-fragment() 3. '<span start="" end="3">Sed</span> ut perspiciatis' => parse-xml-fragment()
-- Tim A. Thompson Metadata Librarian (Spanish/Portuguese Specialty) Princeton University Library
CG
Christian Grün21 Mar 2016 14:25 #
Hi Tim,
Quoted text · Tim Thompson · 3 lines
> The following three expressions illustrate the difference. Numbers 2 and 3 > return parsed XML, whereas number 1 returns the original, unparsed string. > Is this the expected behavior when using string constructors?
Yes, this is how it should be. With plain quotes, entities will be resolved. However, this is not the case when using the string constructor:
  for $string in ('<', ``[<]``)
  return <cp>{ string-to-codepoints($string) }</cp>
Does this help? Christian
Quoted text · Tim Thompson · 11 lines
> 1. > ``[&lt;span start="" end="3"&gt;Sed&lt;/span&gt; ut perspiciatis]`` => > parse-xml-fragment() > > 2. > ``[&lt;span start="" end="3"&gt;Sed&lt;/span&gt; ut perspiciatis]`` => > parse-xml-fragment() => parse-xml-fragment() > > 3. > '&lt;span start="" end="3"&gt;Sed&lt;/span&gt; ut perspiciatis' => > parse-xml-fragment()

⚡Generated with XQuery