Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converting the XML form of resultset to string in C#

Converting the XML form of resultset to string in C#

Scheduled Pinned Locked Moved C#
databasexmlcsharphelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrashantJ
    wrote on last edited by
    #1

    Hi, In my C# application I am trying to execute a SQL query, transform the query results (using XSL) returned in a form of XML, and ultimately want the resutlset as a string in resultSetToAscii. I have started working on C# very recently, so I am sure that I am doing some silly mistake. Basically my code fails in the 3rd line here and the error desc is "Data at root level is invalid". Anybody any ideas? XPathDocument destination; XPathDocument source; source = new XPathDocument(new StringReader("//row")); destination = new XPathDocument(_xsl.Transform(source, null, (XmlResolver)null)); XPathNavigator nav = destination.CreateNavigator(); { XPathNodeIterator iterator = nav.Select("//row"); while (iterator.MoveNext()) { foreach (Field field in _destinationFields) { string data = ""; if (field.name != null) data = iterator.Current.GetAttribute(field.name, String.Empty); resultSetToAscii = data.PadRight(field.size, ' '); } } }

    G 1 Reply Last reply
    0
    • P PrashantJ

      Hi, In my C# application I am trying to execute a SQL query, transform the query results (using XSL) returned in a form of XML, and ultimately want the resutlset as a string in resultSetToAscii. I have started working on C# very recently, so I am sure that I am doing some silly mistake. Basically my code fails in the 3rd line here and the error desc is "Data at root level is invalid". Anybody any ideas? XPathDocument destination; XPathDocument source; source = new XPathDocument(new StringReader("//row")); destination = new XPathDocument(_xsl.Transform(source, null, (XmlResolver)null)); XPathNavigator nav = destination.CreateNavigator(); { XPathNodeIterator iterator = nav.Select("//row"); while (iterator.MoveNext()) { foreach (Field field in _destinationFields) { string data = ""; if (field.name != null) data = iterator.Current.GetAttribute(field.name, String.Empty); resultSetToAscii = data.PadRight(field.size, ' '); } } }

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You are creating a StringReader for the string "//row" and try yo use that as an xml document. The problem is that "//row" is far from a valid xml document. Are you trying to use xpath to read nodes from an xml document? Then you actually have to have an xml document to read from... --- b { font-weight: normal; }

      P 1 Reply Last reply
      0
      • G Guffa

        You are creating a StringReader for the string "//row" and try yo use that as an xml document. The problem is that "//row" is far from a valid xml document. Are you trying to use xpath to read nodes from an xml document? Then you actually have to have an xml document to read from... --- b { font-weight: normal; }

        P Offline
        P Offline
        PrashantJ
        wrote on last edited by
        #3

        Okay I understand. I think the resultset is in the form of xml. I get the resultset by executing this int iRecs = cmd.ExecuteNonQuery(); So what can I pass to this call below? source = new XPathDocument(...) Thanks.

        G 1 Reply Last reply
        0
        • P PrashantJ

          Okay I understand. I think the resultset is in the form of xml. I get the resultset by executing this int iRecs = cmd.ExecuteNonQuery(); So what can I pass to this call below? source = new XPathDocument(...) Thanks.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          The ExecuteNonQuery doesn't return a result, it only returns the number of records affected by the query. So, you don't have any data to start with. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups