SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict ankitaneja1's Avatar
    Join Date
    Sep 2004
    Location
    India
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error while converting string xml to xml using xelement

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

    Code ASP:
    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

    Code ASP:
    XFinalXML = XElement.Parse(strxmlString.ToString())
     
                       xmlResponse = XElement.Parse(XFinalXML.ToString())
                       xmlResponseDoc = New XDocument(xmlResponse)

    pls help
    Last edited by Mittineague; Jul 19, 2011 at 17:14. Reason: reformatting bbcode tags
    Ankit Aneja
    "Nothing is impossible. The word itself says - I M possible"

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why don't you grab the rows this way:

    row["ColumnNameGoesHere"]

    The reason it doesn't work is because "row" has direct access the table, not "i", or what you used.

    Also, I would use a StringBuilder if you are using multiple strings. Saves resources.
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    It is due to the fact that the xml you are generating is not valid.

    This line:
    "<Item code=" + dsGetBVItemDetails.Tables
    (0).Rows(i)(0).ToString() + ">"

    should be:
    "<Item code=\"" + dsGetBVItemDetails.Tables
    (0).Rows(i)(0).ToString() + "\">"

  4. #4
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So? Wouldn't my solution work as well? I have no idea why you would want to access the tables contents that way. Or, if it is possible. That's why I said use the "row" in the "foreach". If not, then what is the point of it?
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  5. #5
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    Yes, your solution will work. I was merely pointing out that the output format of the xml was incorrect. Not what the data code should look like


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •