我正在尝试检查我的xml文件中是否存在HeaderReportUnit,我如何检查此Header是否存在? 我正在使用2.0程序集,非常感谢您的帮助
<?xml version="1.0" encoding="UTF-8" ?>
- <HeadReportUnit>
- <Title>
<ModuleNum>ModuleNum</ModuleNum>
<hdstSetPos>hdstSetPos</hdstSetPos>
<hdstNzlName>hdstNzlName</hdstNzlName>
<nzavSpecName>nzavSpecName</nzavSpecName>
<nzavNzlDiameter>nzavNzlDiameter</nzavNzlDiameter>
<nzavNzlSizeX>nzavNzlSizeX</nzavNzlSizeX>
<nzavNzlSizeY>nzavNzlSizeY</nzavNzlSizeY>
<nzavNzlType2>nzavNzlType2</nzavNzlType2>
</Title>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 1</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 2</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 3</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 4</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 5</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 6</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 7</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 8</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 9</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</nzavNzlSizeX>
<nzavNzlSizeY>0.6</nzavNzlSizeY>
<nzavNzlType2>Standard</nzavNzlType2>
</Unit>
- <Unit>
<ModuleNum>1</ModuleNum>
<hdstSetPos>1- 10</hdstSetPos>
<hdstNzlName>R07-007-070</hdstNzlName>
<nzavSpecName>AA05700</nzavSpecName>
<nzavNzlDiameter>0.0</nzavNzlDiameter>
<nzavNzlSizeX>0.7</
nzavNzlSizeX
答案 0 :(得分:3)
您可以使用XPathNavigator选择节点,看看是否有结果。
例如:
FileStream stream = new FileStream("c:\\file.xml", FileMode.Open);
XPathDocument document = new XPathDocument(stream);
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator node = navigator.Select("/HeadReportUnit");
if (node.Count > 0)
{
// do stuff
}