计算xml文件中元素的数量 [英] Counting number of element in xml file
问题描述
首先,我引用了该帖子如何获取XML或XElement变量中的特定元素计数,并且无法解决我所面临的问题,所以我正在写这篇文章. xml的部分如下所示,我想计算元素的数量,即在modelvariables节点中发生次数标量的数量,如下所示
First of all I referred this post How to get specific element Count in XML or XElement variable and could not solve the problem which i was facing so i am writing this. The part of the xml is given as below I want to count the number of element that is number of occurance scalarvariable in modelvariables node as shown below
<ModelVariables>
<ScalarVariable name="x" valueReference="0" description="the only state"causality="local" variability="continuous" initial="exact">
<Real start="1"/>
</ScalarVariable>
<ScalarVariable name="der(x)" valueReference="1" causality="local" variability="continuous" initial="calculated">
<Real derivative="1"/>
</ScalarVariable>
<ScalarVariable name="k" valueReference="2" causality="parameter" variability="fixed" initial="exact">
<Real start="1"/>
</ScalarVariable>
</ModelVariables>
我定义为
XmlDocument doc =新的XmlDocument(); doc.Load(@"W:\ Prajwal \ FMU_EXTRACT \ modelDescription.xml");
XmlDocument doc = new XmlDocument(); doc.Load(@"W:\Prajwal\FMU_EXTRACT\modelDescription.xml");
我已经将节点列表创建为
and i have created nodelist as
XmlNodeList nodeList = (XmlNodeList)doc.DocumentElement.SelectNodes("//ModelVariables/ScalarVariable");
XmlNodeList nodeList = (XmlNodeList)doc.DocumentElement.SelectNodes("//ModelVariables/ScalarVariable");
我需要获取标量变量
推荐答案
您需要
这篇关于计算xml文件中元素的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!