一分钟学会C#解析XML
发布日期:2021-06-30 19:38:09
浏览次数:2
分类:技术文章
本文共 1022 字,大约阅读时间需要 3 分钟。
如果是只有一种结构的节点,则取到node节点数组,然后遍历即可
例:
private void readXml(string xmlPath) { if (!File.Exists(xmlPath)) { Debug.LogError("file does not exist"); return; } XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlNodeList nodeList = doc.GetElementsByTagName("item"); foreach(XmlNode node in nodeList) { int price = int.Parse(node.Attributes["price"].Value); string name = node.Attributes["name"].Value; } }如果是有多种结构的节点,则需要单独取每个节点解析
例:
private void readXml(string xmlPath) { if (!File.Exists(xmlPath)) { Debug.LogError("file does not exist"); return; } XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlNode root = doc.SelectSingleNode("root"); XmlNode logonData = root.SelectSingleNode("logonData"); string userName = logonData.Attributes["userName"].Value; string pwd = logonData.Attributes["pwd"].Value; }
转载地址:https://linxinfa.blog.csdn.net/article/details/47312833 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年05月02日 22时11分58秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
位图索引Bitmap indexes
2019-04-30
YOLO算法(二)—— Yolov2 & yolo9000
2019-04-30
YOLO算法(三)—— Yolov3 & Yolo系列网络优缺点
2019-04-30
Python的__future__模块
2019-04-30
计算机视觉中的cost-volume的概念具体指什么(代价体积)
2019-04-30
启发函数heuristic 与 A*
2019-04-30
Image Pyramid(图像金字塔)
2019-04-30
Oracle 作业记录
2019-04-30
putty连接AWS配置(multimedia project)
2019-04-30
Hourglass Network 沙漏网络 (pose estimation姿态估计)
2019-04-30
OpenCV实战(二)——答题卡识别判卷
2019-04-30
目标检测神经网络的发展历程(52 个目标检测模型)
2019-04-30
Boundary loss 损失函数
2019-04-30
tensorflow使用tensorboard进行可视化
2019-04-30
凸优化 convex optimization
2019-04-30