ReadXml.cs内容:
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Xml; public class ReadXml : MonoBehaviour { private XmlDocument xmldoc; private XmlNode root; private string url; void Start() { InitAccount(); InitCases(); } void InitAccount() { url = Application.streamingAssetsPath + "/Account_config.xml"; xmldoc = new XmlDocument(); xmldoc.Load(url); root = xmldoc.SelectSingleNode("root"); ReadAccount(); } void ReadAccount() { /*XmlNode account = root.SelectSingleNode("account"); XmlElement ele = (XmlElement)account; Debug.Log(ele.GetAttribute("Username") + " " + ele.GetAttribute("Password"));*/ /*XmlNode usernameNode = root.SelectSingleNode("username"); Debug.Log(((XmlElement)usernameNode).InnerText); XmlElement passwordEle = (XmlElement)root.SelectSingleNode("password"); Debug.Log(passwordEle.InnerText);*/ foreach (var item in root.ChildNodes) { XmlNode xmlNode = item as XmlNode; Debug.Log(xmlNode.Name + ":" + xmlNode.InnerText); } } void InitCases() { url = Application.streamingAssetsPath + "/Cases_config.xml"; xmldoc = new XmlDocument(); xmldoc.Load(url); root = xmldoc.SelectSingleNode("casesList"); ReadCases(); } void ReadCases() { foreach (var item1 in root.ChildNodes) { XmlNode xmlNode1 = item1 as XmlNode; foreach (var item2 in xmlNode1.ChildNodes) { XmlNode xmlNode2 = item2 as XmlNode; Debug.Log(xmlNode2.Name + ":" + xmlNode2.InnerText); } } } }View Code
Cases_config.xml内容:
<?xml version="1.0" encoding="utf-8"?> <casesList> <case> <name>张三三</name> <gender>男</gender> <age>32</age> <chiefComplaint>间断呼吸困难2年,加重伴下肢水肿4天。</chiefComplaint> <historyOfPpresentIllness>患者于3天前疑似因发热服用布洛芬出现便血,暗红色,稀烂便,1天5次,每次约200ml,中途呕血1次,鲜红色,血中有胃内容物,约300ml,伴肚脐上方腹胀。患者面色苍白,有头晕、乏力、口渴,有心悸、反酸,尿量减少。无口腔溃疡、头痛、意识不清,无咳嗽、咳痰、气促,无胸闷、胸痛,无烧心、嗳气、里急后重。患者为求进一步诊治,于1天前来我院急诊就诊,行“血常规”,示“Hb 103g/L”,拟“消化道出血”收入我科。患者自起病以来,胃纳、精神差,睡眠可,大小便如上所述,体重体力无明显变化。</historyOfPpresentIllness> <pastHistory>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</pastHistory> </case> <case> <name>李四四</name> <gender>男</gender> <age>34</age> <chiefComplaint>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</chiefComplaint> <historyOfPpresentIllness>bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb</historyOfPpresentIllness> <pastHistory>yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy</pastHistory> </case> </casesList>View Code
Account_config.xml内容:
<?xml version="1.0" encoding="utf-8"?> <root> <!--<account Username="admin" Password="123456" />--> <username>admin</username> <number>007</number> <department>科室1</department> <group>组1</group> <gender>男</gender> <role>管理员</role> <password>123456</password> </root>View Code
标签:xml,读取,XmlNode,void,Unity,Debug,root,xmldoc From: https://www.cnblogs.com/Peng18233754457/p/18252640