c# - 使用 XML 文件中的组合数据填充组合框
问题描述
我有一个这样的 XML 文件:
<?xml version="1.0"?>
<ArrayOfToolClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ToolClass>
<ToolID>1</ToolID>
<ToolName>Multiflute Endmill</ToolName>
<ToolDia>8</ToolDia>
<ToolTooth>4</ToolTooth>
<ToolApmxs>32</ToolApmxs>
<ToolCuttingSpeed>150</ToolCuttingSpeed>
<ToolFeedPerTooth>0.04</ToolFeedPerTooth>
<ToolAe>8</ToolAe>
<ToolAp>4</ToolAp>
<ToolManufacturer>SECO</ToolManufacturer>
<ToolSerial>DKFLJDSKJ</ToolSerial>
</ToolClass>
<ToolClass>
<ToolID>2</ToolID>
<ToolName>Multiflute Endmill</ToolName>
<ToolDia>4</ToolDia>
<ToolTooth>4</ToolTooth>
<ToolApmxs>25</ToolApmxs>
<ToolCuttingSpeed>235</ToolCuttingSpeed>
<ToolFeedPerTooth>0.03</ToolFeedPerTooth>
<ToolAe>4</ToolAe>
<ToolAp>0.4</ToolAp>
<ToolManufacturer>SECO</ToolManufacturer>
<ToolSerial>DJFKLSL</ToolSerial>
</ToolClass>
</ArrayOfToolClass>
我想将数据填充到组合框:
displaymember= <TooDia>"x"<ToolApmxs>" mm - "<ToolName>;
valuemember=<ToolID>;
我试过这段代码:
var xmlDocument = XDocument.Load(@"data\tools.xml");
var toolist = xmlDocument.Descendants("ToolClass");
但是如何将数据组合成指定的格式呢?
谢谢!
解决方案
所以你可以使用这样的东西来获取第一个成员的内部文本:
var xmlDocument = XDocument.Load(@"data\tools.xml");
var tooList = xmlDocument.GetElementsByTagName("ToolClass").Item(0).InnerText;
推荐阅读
- javascript - React 道具对我不起作用 我正在设计一张卡片
- python - Python - Mailosaur 获取 HTML 元素
- laravel - 如何在编译后的视图文件中执行 javascript(使用 View::render 方法)
- javascript - 如何从超级代理响应中提取 cookie?
- javascript - npm:在上下文中执行?
- javascript - Javascript - 将字符串中的所有字母转换为大写或小写
- python - Python Docker Container:如何安装模块,例如 pymqsl?
- html - HTML 图像标记导致错误“解析 'srcset' 属性值失败,因为它有一个未知的描述符”
- c# - 创建一个通用设置器,我可以使用它来设置类中的任何属性
- node.js - 我已经下载了 nodejs 以进行反应,但是当我的 powershell 打开以安装外部工具时,它给出了图像中显示的错误:-