Solved

Need help with XML

Posted on 2007-03-19
3
200 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now