如何用XPATH解析XML

如何用XPATH解析XML

本文介绍了如何用XPATH解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有两个按钮 - 上一个和下一个。当我运行程序时,它必须向我显示第一个问题,答案是Qtextbox1中的问题。 Atextbox1,Atextbox2,Atextbox3 ... / Key [1]中的答案向我展示了第一个节点。但我不知道如何定义节点数。I have two button - prev and next. When i run program it must show me first question with answers.Question in Qtextbox1. Answers in Atextbox1,Atextbox2,Atextbox3 ... /Key[1] show me first node. But i dont know how define count of nodes. <Key> first question <Value>answer1</Value> <Value>answer2</Value> <Value>answer3</Value> <Value>answer4</Value> <Value>answer5</Value> </Key>- <Key> second question <Value>answer1</Value> <Value>answer2</Value> <Value>answer3</Value> </Key>- <Key> third question <Value>answer1</Value> <Value>answer2</Value> <Value>answer3</Value> </Key>推荐答案XmlDocument xdoc = new XmlDocument();xdoc.LoadXml("Your XML here");XmlNodeList xnodes = xdoc.SelectNodes("/Key");int count = xnodes.Count;foreach (XmlNode xnode in xnodes){ // TODO: Implement your code here}count(//Key/Value) 要获取节点中子元素的数量,我们可以使用以下xpath。 br $>To get the number of child elements in a node, we may use following xpath.count(//Key/*) 这篇关于如何用XPATH解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 17:16