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. Visual Basic
  4. Getting DataTable to clean XML to send over a socket

Getting DataTable to clean XML to send over a socket

Scheduled Pinned Locked Moved Visual Basic
questionsysadminxmlcareer
3 Posts 3 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.
  • N Offline
    N Offline
    Noctris
    wrote on last edited by
    #1

    Hi Guys, In a Client/Server application i was writing, i used XML in my own little protocol to send data between the client and the server in a form something like this: CLIENTID|PROTOCOL_COMMAND_INTEGER|I will be you data for today| Now in the past i've strugled with this xml part because i need encoding that can handle é,è,ç,à and other funny characters like & and stuff.. for this, i could not use datatable.WriteXml(memorystream) (i think) because it always messed up these characters. Being the starting developer that I am , i created a little piece of horrorcode looking like this:

    Public Function GetXmlFromRow(ByVal dr As DataRow, ByVal sRecordType As String) As String
    Dim sb As New IO.StringWriter
    Dim xwXmlTextWriter As New XmlTextWriter(sb)
    xwXmlTextWriter.WriteStartDocument()
    xwXmlTextWriter.WriteStartElement(sRecordType)
    Dim col As DataColumn
    For Each col In dr.Table.Columns
    xwXmlTextWriter.WriteElementString(col.ColumnName, dr.Item(col).ToString)
    Next
    xwXmlTextWriter.WriteEndDocument()
    xwXmlTextWriter.Flush()
    Return sb.ToString
    End Function

    It isn't pretty.. but it does the job. Now however, i ran into trouble: i need to send a blob in this XML (a blob which contains another XML file :s). however, i cannot do a ".ToString" from a blob cause it just returns the datatype name as a string. How can i get a decent formatted XML file from a datatable to send over a socket OR Do i need to rethink my solution completly ? If so: What is the best way/protocol to handle these kinds of things ? Thanks !

    M B 2 Replies Last reply
    0
    • N Noctris

      Hi Guys, In a Client/Server application i was writing, i used XML in my own little protocol to send data between the client and the server in a form something like this: CLIENTID|PROTOCOL_COMMAND_INTEGER|I will be you data for today| Now in the past i've strugled with this xml part because i need encoding that can handle é,è,ç,à and other funny characters like & and stuff.. for this, i could not use datatable.WriteXml(memorystream) (i think) because it always messed up these characters. Being the starting developer that I am , i created a little piece of horrorcode looking like this:

      Public Function GetXmlFromRow(ByVal dr As DataRow, ByVal sRecordType As String) As String
      Dim sb As New IO.StringWriter
      Dim xwXmlTextWriter As New XmlTextWriter(sb)
      xwXmlTextWriter.WriteStartDocument()
      xwXmlTextWriter.WriteStartElement(sRecordType)
      Dim col As DataColumn
      For Each col In dr.Table.Columns
      xwXmlTextWriter.WriteElementString(col.ColumnName, dr.Item(col).ToString)
      Next
      xwXmlTextWriter.WriteEndDocument()
      xwXmlTextWriter.Flush()
      Return sb.ToString
      End Function

      It isn't pretty.. but it does the job. Now however, i ran into trouble: i need to send a blob in this XML (a blob which contains another XML file :s). however, i cannot do a ".ToString" from a blob cause it just returns the datatype name as a string. How can i get a decent formatted XML file from a datatable to send over a socket OR Do i need to rethink my solution completly ? If so: What is the best way/protocol to handle these kinds of things ? Thanks !

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Hmmm seems you have 2 distinct problems. 1. Unicode in a client dataset - I'm sure it can be done, but I have not had the requirement.

      Noctris wrote:

      How can i get a decent formatted XML file from a datatable

      2. Datatabe/set to xlm is simply xmlDataset.writexml(memorystream/variable) I think!

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N Noctris

        Hi Guys, In a Client/Server application i was writing, i used XML in my own little protocol to send data between the client and the server in a form something like this: CLIENTID|PROTOCOL_COMMAND_INTEGER|I will be you data for today| Now in the past i've strugled with this xml part because i need encoding that can handle é,è,ç,à and other funny characters like & and stuff.. for this, i could not use datatable.WriteXml(memorystream) (i think) because it always messed up these characters. Being the starting developer that I am , i created a little piece of horrorcode looking like this:

        Public Function GetXmlFromRow(ByVal dr As DataRow, ByVal sRecordType As String) As String
        Dim sb As New IO.StringWriter
        Dim xwXmlTextWriter As New XmlTextWriter(sb)
        xwXmlTextWriter.WriteStartDocument()
        xwXmlTextWriter.WriteStartElement(sRecordType)
        Dim col As DataColumn
        For Each col In dr.Table.Columns
        xwXmlTextWriter.WriteElementString(col.ColumnName, dr.Item(col).ToString)
        Next
        xwXmlTextWriter.WriteEndDocument()
        xwXmlTextWriter.Flush()
        Return sb.ToString
        End Function

        It isn't pretty.. but it does the job. Now however, i ran into trouble: i need to send a blob in this XML (a blob which contains another XML file :s). however, i cannot do a ".ToString" from a blob cause it just returns the datatype name as a string. How can i get a decent formatted XML file from a datatable to send over a socket OR Do i need to rethink my solution completly ? If so: What is the best way/protocol to handle these kinds of things ? Thanks !

        B Offline
        B Offline
        BDEz Member 3919223
        wrote on last edited by
        #3

        You will need to run a REGEX session on your string before you send it to your XMLWriter. Search GOOGLE for xml unsafe characters and ASCII code to see what you should turn those funny characters into. Since you are making your own server / client application you can set your own REGEX standards for conversion of characters. IE: REGEX finds a "&" in your input string. You replace "&" with a @045; and send that to your XMLWriter.

        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