Hello BaseX team,
I need to insert a node that has an attribute with two double quotes.
An example: let $message:='<Amt Ccy=""GBP"">3.00</Amt>' return insert nodes fn:parse-xml-fragment($message) as last into doc('testingdb/testing.xml')
The GBP attribute is with two " so it gives the error: SAX: file://C:/Program$20Files(86)/BaseX/(Line1)file:///C:/Program$20Files(86)/BaseX/(Line1): whitespace expected, attribute name found.
How can I solve the issue?
P Respectons ensemble l'environnement. N'imprimez ce message que si n?cessaire. Let's respect the environment together. Only print this message if necessary.
Am 27.07.2020 um 12:01 schrieb Ramzi Hammouda:
Hello BaseX team,
I need to insert a node that has an attribute with two double quotes.
An example:
let $message:='<Amt Ccy=""GBP"">3.00</Amt>'
With XML markup, to have an attribute value delimited by double quotes but to also use double quotes inside the attribute value, you need to use an entity reference or character reference in the attribute value <Amt Ccy=""GBP"">3.00</Amt> to escape the double quote(s).
return insert nodes fn:parse-xml-fragment($message)
as last into doc('testingdb/testing.xml')
The GBP attribute is with two “ so it gives the error:
SAX: file://C:/Program$20Files(86)/BaseX/(Line1) file:///C:/Program$20Files(86)/BaseX/(Line1): whitespace expected, attribute name found.
How can I solve the issue?
P/Respectons ensemble l'environnement. N'imprimez ce message que si nécessaire. //Let's respect the environment together. Only print this message if necessary./
With XML markup, to have an attribute value delimited by double quotes but to also use double quotes inside the attribute value, you need to use an entity reference or character reference in the attribute value <Amt Ccy=""GBP"">3.00</Amt> to escape the double quote(s).
If you have full control over the query generation process, you could also use an XQuery 3.1 String Constructor (``[ ... ]``) for the XML snippet and simple quotes for the attribute value:
let $message:= ``[<Amt Ccy='"GBP"'>3.00</Amt>]`` return insert nodes fn:parse-xml-fragment($message) as last into doc('testingdb/testing.xml')
Your query could be simplified to…
let $node := <Amt Ccy='"GBP"'>3.00</Amt> return insert node $node into doc('testingdb/testing.xml')
…but I guess you have reasons for using parse-xml-fragment.
basex-talk@mailman.uni-konstanz.de