?
Solved

Need help with XML

Posted on 2007-03-19
3
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 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