XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ahmad AbusalahSubject: Xquery XML document with spceial characters
Author: Ahmad Abusalah
Date: 09 Mar 2010 01:31 PM
Hello,

I am using Stylus Studio Enterprise 2010.

I am running an Xquery that will access an XML document and retrieve the data (value) of some elements.

My XML document has elements like:
<WI>
<CODE>

insert into table_name(Col_1, Col_2)
values ('A & D', 'A-->B');

</CODE>
</WI>

Here is the Xquery I am using:
for $x in doc("C://test1.xml")/WI
return data($x/CODE)
else ()

The problem that I have is I got error because of the & and > in the element above.

I want to be able to run my Xquery and just return those special characters as is. Not sure how to do it!!

Thanks,

Postnext
Ivan PedruzziSubject: Xquery XML document with spceial characters
Author: Ivan Pedruzzi
Date: 09 Mar 2010 03:36 PM
test1.xml is not a valid XML document, it should either escape the offending characters with entities

<WI>
<CODE>
insert into table_name(Col_1, Col_2)
values ('A &amp; D', 'A--&gt;B');
</CODE>
</WI>

or wrapping the value with a CDATA section

<WI>
<CODE><![CDATA[
insert into table_name(Col_1, Col_2)
values ('A & D', 'A-->B');
]]></CODE>
</WI>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Ahmad AbusalahSubject: Xquery XML document with spceial characters
Author: Ahmad Abusalah
Date: 10 Mar 2010 10:33 AM
Originally Posted: 10 Mar 2010 10:34 AM
Thanks Ivan for the reply,

If I ran my xquery using either of the modifications your proposed, I will get the following output:

insert into table_name(Col_1, Col_2)
values ('A &amp; D', 'A--&gt;B');

But the output that I really want is:

insert into table_name(Col_1, Col_2)
values ('A & D', 'A-->B');

Not sure how to keep the & and > as is in the output and not changed to &amp; or &gt; in my output.

Thank you again

Postnext
Ivan PedruzziSubject: Xquery XML document with spceial characters
Author: Ivan Pedruzzi
Date: 10 Mar 2010 06:27 PM

Hi Ahmad,

You should not be concern about the serialization form.

The text you are seeing is valid XML, therefore any XML parser will take it. Notice that after going through a parser the text node will be properly re-escaped.

Another option is to use a cdata-section with the DataDirect XQuery
The following wraps the text node with a CDATA

declare option ddtek:serialize "cdata-section-elements=CODE";

declare variable $cd :=
<WI>
<CODE>
insert into table_name(Col_1, Col_2)
values ('A &amp; D', 'A-->B');
</CODE>
</WI>;

$cd


Ivan Pedruzzi
Stylus Studio Team

Postnext
Ahmad AbusalahSubject: Xquery XML document with spceial characters
Author: Ahmad Abusalah
Date: 11 Mar 2010 01:57 PM
Let me elaborate on how we are using the above Xquery.

We are evaluating an idea where we will push all work items (WI) with code changes as elements in one big XML file. Each WI element consists of many elements and one of those will be <CODE>.

We will run the Xquery above to get the contents of those code elements.

The output of above Xquery will be SQL script that will be used as part of an automated process.

Therefore, I am concerned about the output to exactly match the contents of <code> elements. So, I want & to appear as & and not as &amp; in the output. The same thing for < and >.


I proposed the use of StylusStudio Enterprise edition and currently we are using the evlaution copy of it to do a proof of concept.

Thanks,

Postnext
Ivan PedruzziSubject: Xquery XML document with spceial characters
Author: Ivan Pedruzzi
Date: 11 Mar 2010 02:57 PM
If the XQuery result is a SQL statement than you can switch to method=text

Does it help?

declare option ddtek:serialize "method=text";
declare variable $cd :=
<WI>
<CODE>
insert into table_name(Col_1, Col_2) values ('A &amp; D', 'A-->B');
</CODE>
</WI>;

data($cd/CODE)

output
----------

insert into table_name(Col_1, Col_2) values ('A & D', 'A-->B');


BTW are you aware that our XQuery engine allows you to execute SQL update statements against almost all major database products (SQL Server, DB2, Oracle, Sybase, MySQL, Informix) direclty from your query?

Here is an example
ddtek:sql-insert("table_name", "Col_1", "A &amp; D", "Col_1", "A-->B")

Ivan Pedruzzi
Stylus Studio Team

Posttop
Ahmad AbusalahSubject: Xquery XML document with spceial characters
Author: Ahmad Abusalah
Date: 14 Mar 2010 04:17 PM
Thank you Ivan. I got it.. It works now.

Thank you again :)

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.