如何解决客户端服务器应用程序中XML的多根问题? [英] How to fix multiple root problem in XML within client server application??
问题描述
我正在使用vb.net开发多线程Messenger.
这个想法很简单.通过客户端服务器发送XML数据.我使用线程将ping从服务器发送到客户端.但是,XML是合谋的.因此,客户端或服务器无法读取它,从而导致XML异常:有多个根元素.第13行,位置20."
我该如何解决?
谢谢,
Dwi Prawira
注意:发送和接收数据时,我使用dataset.writexml()进行流传输和dataset.readxml()
这是我发送和接收数据的代码..
I am developing a multithreading messenger using vb.net
The idea is simple. sending a XML data through client server. I use thread to sending ping from server to client. but, the XMLs are colide. So the client or server can''t read it, causing XML exception : "There are multiple root elements. Line 13, position 20."
how can i fix it?
Thanks,
Dwi Prawira
note: i use dataset.writexml() to stream and dataset.readxml() when sending and receiving data
here is my code for sending and receiving data..
Public Sub SendRequest(ByVal data As clsXMLData, ByVal cl As TcpClient)
Dim xmlDoc As New Xml.XmlDocument()
Dim dt As New DataTable("SendResponse")
dt.Columns.Add("Action")
dt.Columns.Add("Value1")
dt.Columns.Add("Value2")
dt.Columns.Add("Value3")
dt.Columns.Add("Value4")
dt.Columns.Add("Value5")
dt.Columns.Add("Value6")
dt.Columns.Add("Value7")
dt.Columns.Add("Value8")
dt.Rows.Add(data.Action, data.Value1, data.Value2, data.Value3, data.Value4, _
data.Value5, data.Value6, data.Value7, data.Value8)
Dim strm As NetworkStream = cl.GetStream
dt.WriteXml(strm)
strm.Flush()
End Sub
Public Function ReceiveResponse(ByVal strm As NetworkStream, _
ByVal cl As TcpClient) As clsXMLData
Dim ds As New DataSet("ReceiveResponse")
ds.ReadXml(NetToMemStream(strm, cl))
Dim data As New clsXMLData
With data
.Action = ds.Tables(0).Rows.Item(0).Item(0)
.Value1 = ds.Tables(0).Rows.Item(0).Item(1)
.Value2 = ds.Tables(0).Rows.Item(0).Item(2)
.Value3 = ds.Tables(0).Rows.Item(0).Item(3)
.Value4 = ds.Tables(0).Rows.Item(0).Item(4)
.Value5 = ds.Tables(0).Rows.Item(0).Item(5)
.Value6 = ds.Tables(0).Rows.Item(0).Item(6)
.Value7 = ds.Tables(0).Rows.Item(0).Item(7)
.Value8 = ds.Tables(0).Rows.Item(0).Item(8)
End With
Return data
End Function
推荐答案
仅一次只处理一个XML文件?
By only dealing with one XML file at a time ?
听起来像您允许线程使用相同的xml文档或文件.
但这是一个猜测,因为您的叙述很少,并且缺少与您的问题相关的任何代码段
sounds like you are allowing the threads to use the same xml document or file.
but that is a guess as your narrative is sparse and lacks any code snippets relevant to your question
这篇关于如何解决客户端服务器应用程序中XML的多根问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!