Solved

Need help with XML

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to call weather service by using asmx? 4 29
Hey!!!! 1 20
Firing an ASP.NET event on selection of a JQuery datepicker 4 15
C# Gridview 1 29
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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