<career code="17-1011.00">
<code>17-1011.00</code>
<title>Architects</title>
<tags bright_outlook="false" green="true" apprenticeship="false" />
<also_called>
<title>Architect</title>
<title>Project Architect</title>
<title>Project Manager</title>
<title>Architectural Project Manager</title>
</also_called>
<what_they_do>Plan and design structures, such as private residences, office buildings, theaters, factories, and other structural property.</what_they_do>
<on_the_job>
<task>Consult with clients to determine functional or spatial requirements of structures.</task>
<task>Prepare scale drawings.</task>
<task>Plan layout of project.</task>
</on_the_job>
</career>
我已经获取了从 ONet 返回的这个 XML,并希望解析要使用的信息。这是我编写的代码,用于尝试解析 下标签的内部文本,“输入”是 Onet XML。
XmlDocument inputXML = new XmlDocument();
inputXML.LoadXml(input);
XmlElement root = inputXML.DocumentElement;
XmlNodeList titleList = root.GetElementsByTagName("also_called");
for (int i = 0; i < titleList.Count; i++)
{
Console.WriteLine(titleList[i].InnerText);
}
我期待一个大小为 4 的 NodeList。但是,当我打印出结果时,结果的大小为 1:“ArchitectProject ArchitectProject ManagerArchitectural Project Manager”
我是否构建了我的 XMLNodeList titleList 错误?如何进一步遍历和处理 XML 树以获取“also_call”下的“标题”标签的内部值?