I've been trying to implement ReadXMLString method on the UltraWebTree but keep getting an 'Object Reference not set to an instance of an object' exception thrown. Interestingly the XMl string I'm reading back in was originally generated by the WriteXMLString function with no issues. My short code snippet follows:
Private Sub BuildTreeDR() Dim ConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ChepGAP2v2ConnectionString").ConnectionString Dim obConn As New SqlConnection(ConnectionString) Dim sql As String = "SELECT TOP 1 BookXML FROM tblTest" Dim XMLString As String Using obConn Dim cmd As New SqlCommand(sql, obConn) Try obConn.Open() XMLString = Convert.ToString(cmd.ExecuteScalar()) ' XMLString is initialized with the XML structure at this point Me.UltraWebTree1.ReadXmlString(XMLString, True, True) obConn.Close() Catch ex As Exception ' ex.Message = "Object reference not set to an instance of an object." MsgBox(ex.Message) End Try End Using End Sub
Any insite into the problem would be greatly appreciated.
Write/ReadXmlDoc are intended for save/restore state (although you can certainly use them in other cases). So the only way to use ReadXmlDoc is to use the very same format you've got from WriteXmlDoc before. This could be tricky.
I believe the standard way to bind Xml to the treeview is to use the declarative XmlDataSource control Please, take a look at the following search (binding XmlDataSource to UltraWebTree) in our forums - some of the forum threads there are a direct match for what you need.
Thanks for the fast reply Rumen on the ReadXMLDoc (actually I'm using ReadXMLString but that shouldn't matter).
Further testing reveled that because I was using the datatype XML in SQL server it was returning an incomplete xml structure to the ReadXMLDoc method. The problem being the preamble '<?xml version="1.0" encoding="utf-8" standalone="yes"?> 'was not supplied by the query. Once this was appended to the top of the XML it became straight forward in constructing the tree on the SQL server then supplying the xml string via a stored procedure output parameter directly to the web tree. The end result is a blindingly fast tree build.
We build almost all of our XML structures dynamically on SQL 2005 server so the prospect of loading the web tree this way is very appealing. Once we saw that we could apply stylesheets via the xml to the tree we thought this would work perfect for our application. We do not need to bind to the tree as we refresh the tree anytime a node is modified/added/deleted
Again thanks for your assistance.
Don Reinhart
Coral C Software Pty Ltd