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. error while converting string xml to xml using xelement

error while converting string xml to xml using xelement

Scheduled Pinned Locked Moved Visual Basic
xmldatabasehelp
6 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.
  • A Offline
    A Offline
    Ankit Aneja
    wrote on last edited by
    #1

    Hi All I am making a string from dataset and then converting to xml.while converting its giving me error unexpected symbol "=" at location

    For Each row In dsGetBVItemDetails.Tables(0).Rows
    strxmlString += _
    "<ItemDetails>" & _
    "<Item code=" + dsGetBVItemDetails.Tables
    (0).Rows(i)(0).ToString() + ">" &
    _
    "<Description>" +
    dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _
    "</Item>" & _
    "<ItemQty>" + dsGetBVItemDetails.Tables
    (0).Rows(i)(2).ToString() + "</ItemQty>" & _
    "<Message>" + dsGetBVItemDetails.Tables
    (0).Rows(i)(3).ToString() + "</Message>" & _
    "</ItemDetails>"
    i = i + 1
    Next

    It is giving error while converting only when adding attribute "code" in element Item pls suggest and then converting like this

    XFinalXML = XElement.Parse(strxmlString.ToString())

                   xmlResponse = XElement.Parse(XFinalXML.ToString())
                   xmlResponseDoc = New XDocument(xmlResponse)
                   schemaResponse.Add(Constants.TARGETNAMESPACE, AppDomain
    

    .CurrentDomain.BaseDirectory & "Schema\" & Constants.GetBVItemsResponse)
    nsResponse = xmlResponseDoc.Root.Name.NamespaceName

    Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

    L D 2 Replies Last reply
    0
    • A Ankit Aneja

      Hi All I am making a string from dataset and then converting to xml.while converting its giving me error unexpected symbol "=" at location

      For Each row In dsGetBVItemDetails.Tables(0).Rows
      strxmlString += _
      "<ItemDetails>" & _
      "<Item code=" + dsGetBVItemDetails.Tables
      (0).Rows(i)(0).ToString() + ">" &
      _
      "<Description>" +
      dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _
      "</Item>" & _
      "<ItemQty>" + dsGetBVItemDetails.Tables
      (0).Rows(i)(2).ToString() + "</ItemQty>" & _
      "<Message>" + dsGetBVItemDetails.Tables
      (0).Rows(i)(3).ToString() + "</Message>" & _
      "</ItemDetails>"
      i = i + 1
      Next

      It is giving error while converting only when adding attribute "code" in element Item pls suggest and then converting like this

      XFinalXML = XElement.Parse(strxmlString.ToString())

                     xmlResponse = XElement.Parse(XFinalXML.ToString())
                     xmlResponseDoc = New XDocument(xmlResponse)
                     schemaResponse.Add(Constants.TARGETNAMESPACE, AppDomain
      

      .CurrentDomain.BaseDirectory & "Schema\" & Constants.GetBVItemsResponse)
      nsResponse = xmlResponseDoc.Root.Name.NamespaceName

      Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Are you adding double quote characters around the attribute value that follows "<Item code="? You can check this by looking at the generated string in your debugger.

      The best things in life are not things.

      A 1 Reply Last reply
      0
      • L Lost User

        Are you adding double quote characters around the attribute value that follows "<Item code="? You can check this by looking at the generated string in your debugger.

        The best things in life are not things.

        A Offline
        A Offline
        Ankit Aneja
        wrote on last edited by
        #3

        yes below is my code For Each row In dsGetBVItemDetails.Tables(0).Rows strxmlString += _ "<ItemDetails>" & _ "<Item code=" + dsGetBVItemDetails.Tables (0).Rows(i)(0).ToString() + ">" & _ "<Description>" + dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _ "</Item>" & _ "<ItemQty>" + dsGetBVItemDetails.Tables (0).Rows(i)(2).ToString() + "</ItemQty>" & _ "<Message>" + dsGetBVItemDetails.Tables (0).Rows(i)(3).ToString() + "</Message>" & _ "</ItemDetails>" i = i + 1 Next

        Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

        D L 2 Replies Last reply
        0
        • A Ankit Aneja

          Hi All I am making a string from dataset and then converting to xml.while converting its giving me error unexpected symbol "=" at location

          For Each row In dsGetBVItemDetails.Tables(0).Rows
          strxmlString += _
          "<ItemDetails>" & _
          "<Item code=" + dsGetBVItemDetails.Tables
          (0).Rows(i)(0).ToString() + ">" &
          _
          "<Description>" +
          dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _
          "</Item>" & _
          "<ItemQty>" + dsGetBVItemDetails.Tables
          (0).Rows(i)(2).ToString() + "</ItemQty>" & _
          "<Message>" + dsGetBVItemDetails.Tables
          (0).Rows(i)(3).ToString() + "</Message>" & _
          "</ItemDetails>"
          i = i + 1
          Next

          It is giving error while converting only when adding attribute "code" in element Item pls suggest and then converting like this

          XFinalXML = XElement.Parse(strxmlString.ToString())

                         xmlResponse = XElement.Parse(XFinalXML.ToString())
                         xmlResponseDoc = New XDocument(xmlResponse)
                         schemaResponse.Add(Constants.TARGETNAMESPACE, AppDomain
          

          .CurrentDomain.BaseDirectory & "Schema\" & Constants.GetBVItemsResponse)
          nsResponse = xmlResponseDoc.Root.Name.NamespaceName

          Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You're missing quotes around the value for code. Concatentating string together to build an XML document is doing it the hard way and it's less forgiving of typos and invalid characters in the contents. You might want to look into building it this way:

          Dim xml As New XDocument
          
          xml.Declaration = New XDeclaration("1.0", "utf-8", "yes")
          
          Dim rootNode As New XElement("RootNode")
          
          For index = 1 To 3
              rootNode.Add(<ItemDetails>
                               <Item code=<%= index %>>
                                   <Description>Some description text <%= index %></Description>
                               </Item>
                               <ItemQty><%= index %></ItemQty>
                                   <Message>Item Message <%= index %></Message>
                           </ItemDetails>)
          Next
          
          xml.Add(rootNode)
          
          Debug.WriteLine(xml.ToString)
          

          Notice that any values are automatically put into quotes when needed. Plus, you get full Intellisense support and syntax checking in Visual Studio 2010.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          1 Reply Last reply
          0
          • A Ankit Aneja

            yes below is my code For Each row In dsGetBVItemDetails.Tables(0).Rows strxmlString += _ "<ItemDetails>" & _ "<Item code=" + dsGetBVItemDetails.Tables (0).Rows(i)(0).ToString() + ">" & _ "<Description>" + dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _ "</Item>" & _ "<ItemQty>" + dsGetBVItemDetails.Tables (0).Rows(i)(2).ToString() + "</ItemQty>" & _ "<Message>" + dsGetBVItemDetails.Tables (0).Rows(i)(3).ToString() + "</Message>" & _ "</ItemDetails>" i = i + 1 Next

            Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            No, you're not. The resulting string code should be closer to:

            " & \_
            

            But, you shouldn't even be doing it this way. You're code is nearly impossible to read and makes it very difficult yo see what's going on. Look at my other reply.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            1 Reply Last reply
            0
            • A Ankit Aneja

              yes below is my code For Each row In dsGetBVItemDetails.Tables(0).Rows strxmlString += _ "<ItemDetails>" & _ "<Item code=" + dsGetBVItemDetails.Tables (0).Rows(i)(0).ToString() + ">" & _ "<Description>" + dsGetBVItemDetails.Tables(0).Rows(i)(1).ToString() + "</Description>" & _ "</Item>" & _ "<ItemQty>" + dsGetBVItemDetails.Tables (0).Rows(i)(2).ToString() + "</ItemQty>" & _ "<Message>" + dsGetBVItemDetails.Tables (0).Rows(i)(3).ToString() + "</Message>" & _ "</ItemDetails>" i = i + 1 Next

              Ankit Aneja "Nothing is impossible. The word itself says - I M possible"

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              To add to Dave's comments, you have ignored my suggestion and merely reposted the original code, minus the <pre> tags, so it's almost impossible to read. And it obviously does not include the double quotes; had you used your debugger you would have spotted that fairly quickly.

              The best things in life are not things.

              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