Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2005, 11:10 AM
Authorized User
 
Join Date: Feb 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default I Need to Read an Xml from String

I need to read an xml from string(parse the xml based on the element name).The Xml (string) is retrieved from database and is stored in a string and is passed in the loadxml(stringname)..but its showing error in the particular location as token should seek for end element..try to find me the solution as i couldn't able to get the solution for this particular scenario in net and i also had posted the code along with this mail....And if possible send me the solution to my personal mail id too([email protected])


CODE:
If Page.IsPostBack = True Then
            Dim strxml As String
            Dim cn As New SqlConnection("Server=EPROINDIA55;uid=sa;pwd=sensi ple;database=NorthWind")
            Dim str As String
            str = "Select xmlval from detail where id='" + DropDownList1.SelectedItem.Text + "'"
            Dim cmd As New SqlCommand(str, cn)
            cn.Open()
            Dim rd As SqlDataReader
            rd = cmd.ExecuteReader()
            While rd.Read()
                With rd
                    strxml = .Item("xmlval")
                End With
            End While
            Response.Write(strxml)

            Dim a As String
            a = TextBox1.Text
            Dim reader As XmlNodeReader = Nothing

            Try
                Dim doc As New XmlDocument
//ERROR IS POINTED IN THE FOLLOWING LINE
                doc.LoadXml(strxml)

                reader = New XmlNodeReader(doc)
                reader.MoveToContent()
                While reader.Read()
                    Select Case reader.NodeType
                        Case XmlNodeType.Element
                            If reader.Name = TextBox4.Text Then
                                'Response.Write((reader.Name & "='" & reader.ReadInnerXml & "'"))
                                TextBox1.Text = reader.ReadInnerXml
                                TextBox2.Text = reader.ReadInnerXml
                                TextBox3.Text = reader.ReadInnerXml
                            End If
                    End Select
                End While
            Finally
                If Not (reader Is Nothing) Then
                    reader.Close()
                End If
            End Try
        End If

 
Old February 24th, 2005, 11:35 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks as if the "Xml" that you're reading isn't well-formed XML, in other words, it isn't XML at all. The only thing you can do is try to find out why and fix the problem at source.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 25th, 2005, 02:01 AM
Authorized User
 
Join Date: Feb 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have Read the same XML when i stored it in file and read it from there,but in the case of storing it as string and reading it,i couldn't able to read it.And the XML which i'm trying to read is defnitely wellformed.

 
Old March 18th, 2005, 12:04 AM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am a chinese and not be good at english!Help me!






Similar Threads
Thread Thread Starter Forum Replies Last Post
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM
read a string from a comport john.wijnands Access VBA 1 September 8th, 2003 10:59 PM
How to read a string with a space? megabytes C# 4 August 1st, 2003 03:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.