java xml 多个根元素,有多个根元素加载XML

sRecieved = "2.03.0"

Dim xml As New XmlDocument();

xml.LoadXml(sRecieved);

There are multiple root elements .....i want xmlclient value and xmlversion value

解决方案

Well yes, your data isn't a valid XML document. (The error message is pretty clear - you've got multiple top-level elements.) You could make it a valid document by adding a dummy root element:

xml.LoadXml("" & sReceived & "")

... but if you get the chance to change whatever's sending the data, it would be better if it sent an actual XML document.

EDIT: If you're able to use LINQ to XML instead of XmlDocument, getting the client number and the version number are easy. For example, as text:

Dim clientVersion = doc.Root.Element("XmlClient").Value

Dim xmlVersion = doc.Root.Element("XmlVersion").Value

EDIT: Okay, if you're stuck with XmlDocument, I believe you could use:

Dim clientVersionNode = doc.DocumentElement.GetElementsByTagName("XmlClient")(0)

Dim clientVersion = (CType(clientVersionNode, XmlElement)).InnerText

(and likewise for xmlVersion)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值