Solved

Need help with XML

Posted on 2007-03-19
3
205 Views
Last Modified: 2011-09-20
Hi,

I have an xml element that looks like the following:

<SQLQuery>
      <![CDATA[
            SELECT
                  P.Name,
      P.ID,
      P.Address,
     etc......

      FROM        
        Person P
      INNER JOIN Department D ON D.PersonID = P.ID
     etc.....
      WHERE    
        P.HireDate > { d '2002-01-01'})]]>
    </SQLQuery>


When I attempt to parse the <SQLQuery> element, my text looks like the following:

"<![CDATA[\r\n\t\tSELECT\r\n\t\t      P.Name,\r\n     etc........."

this is how I attempt to extract the text of my SQLQuery element.
string sql = dsNode.SelectSingleNode("SQLQuery").InnerXml.Trim();

thanks...


0
Comment
Question by:brdrok
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 18750781
It does not look to me like you have a problem (if you do, tell us, please!)

If you are worried about the \r \n\t characters in your string, those simply represent the carriage returns, linefeeds and tabs in the text you provided.  That is as it should be.  You can always replace those with spaces if you want everything on one line.
0
 
LVL 7

Author Comment

by:brdrok
ID: 18751090
Heya Jens,

the thing is that I am going to use it as part of a sql query, thus, characters such as "\t\r\n" or CDATA is invalid.

For the time being, I am using the Replace() function, but I was hoping that there is a better way of doing it.

thanks
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 18753910
Sounds reasonable.  The OTHER option is to NOT put those characters in there in the first place, if the XML is under your control.

I.e.,  instead of

<![CDATA[
            SELECT
                  P.Name,
      P.ID,
      P.Addres
do

<![CDATA[SELECT P.Name, P.ID, P.Addres

etc.

Trying to do fancy formatting inside a CDATA sticks you with unwanted formatting in the output!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question