AI智能
改变未来

xml文件读写(C#)

```markup```handlebars<?xml version=\"1.0\" encoding=\"utf-8\"?><PETGantrySimulator><Product type=\"uMI550\"><ScanMode type=\"Coincidence\"><SystemStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI550\\CoincidenceSystemStatus\\SystemStatusData.xml</SystemStatus></ScanMode><ScanMode type=\"Single\"><SystemStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI550\\SingleSystemStatus\\SystemStatusData.xml</SystemStatus></ScanMode><SystemMonitorStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI550\\SymInfo\\GCCSYM.xml</SystemMonitorStatus><OverTempStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI550\\SymInfo\\SymInfoNode.xml</OverTempStatus><Protocols><Protocol type=\"PETTOFCalibrationphantom\"><RawData bedNum=\"1\"><Bed index=\"0\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI550\\CoincidenceRawData\\TOF\\Coincidence_RawData</Bed></RawData></Protocol><Protocol type=\"PETLUTScan\"><RawData bedNum=\"1\"><Bed index=\"0\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI550\\SingleAcqRawData\\LUT\\SingleAcq_RawData</Bed></RawData></Protocol></Protocols></Product><Product type=\"uMI880\"><ScanMode type=\"Coincidence\"><SystemStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI880\\CoincidenceSystemStatus\\SystemStatusData.xml</SystemStatus></ScanMode><ScanMode type=\"Single\"><SystemStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI880\\SingleSystemStatus\\SystemStatusData.xml</SystemStatus></ScanMode><Protocols><Protocol type=\"PETTOFCalibrationphantom\"><RawData bedNum=\"1\"><Bed index=\"0\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI880\\CoincidenceRawData\\TOF\\Coincidence_RawData</Bed></RawData></Protocol><Protocol type=\"PETLUTScan\"><RawData bedNum=\"1\"><Bed index=\"0\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI880\\SingleRawData\\LUT\\Single_raw_data</Bed></RawData></Protocol></Protocols></Product><Product type=\"uMIX2000\"><ScanMode type=\"Coincidence\"><SystemStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI880\\CoincidenceSystemStatus\\SystemStatusData.xml</SystemStatus></ScanMode><ScanMode type=\"Single\"><SystemStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMI880\\SingleSystemStatus\\SystemStatusData.xml</SystemStatus></ScanMode><SystemMonitorStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\SymInfo\\GCCSYM.xml</SystemMonitorStatus><OverTempStatus>D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\SymInfo\\SymInfoNode.xml</OverTempStatus><Protocols><Protocol type=\"PETTOFCalibrationphantom\"><RawData bedNum=\"4\"><Bed index=\"0\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\CoincidenceRawData\\TOF\\Coincidence_RawData</Bed><Bed index=\"1\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\CoincidenceRawData\\TOF\\Coincidence_RawData</Bed><Bed index=\"2\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\CoincidenceRawData\\TOF\\Coincidence_RawData</Bed><Bed index=\"3\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\CoincidenceRawData\\TOF\\Coincidence_RawData</Bed></RawData></Protocol><Protocol type=\"PETLUTScan\"><RawData bedNum=\"4\"><Bed index=\"0\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\SingleRawData\\LUT\\Single_raw_data</Bed><Bed index=\"1\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\SingleRawData\\LUT\\Single_raw_data</Bed><Bed index=\"2\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\SingleRawData\\LUT\\Single_raw_data</Bed><Bed index=\"3\">D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Data\\uMIX2000\\SingleRawData\\LUT\\Single_raw_data</Bed></RawData></Protocol></Protocols></Product></PETGantrySimulator>
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;namespace XMLOperate{class Program{static string m_filePath = @\"D:\\UIH\\appdata\\MI\\Simulator\\PETGantry\\Config\\MIPETSimulator_FilePathConfig.xml\";static private XmlDocument m_docXml = null;static void Main(string[] args){m_docXml = new XmlDocument();m_docXml.Load(m_filePath);GetRawDataFilePathByProtocalKeyAndBedNo(Product.uMI880, \"PETTOFCalibrationphantom\", ScanMode.Coincidence, 0);GetRawDataFilePathByProtocalKeyAndBedNo(Product.uMIX2000, \"PETLUTScan\", ScanMode.Single, 2);GetSystemStatusFilePath(Product.uMI880,ScanMode.Coincidence);GetSymInfoSystemMonitorStatusFilePath(Product.uMI550,ScanMode.Coincidence);GetSymInfoOverTempFilePath(Product.uMI550,ScanMode.Coincidence);}public static string GetSystemStatusFilePath(Product product, ScanMode model){if (null != m_docXml){string xPath = string.Format(\"/PETGantrySimulator/Product[@type=\'{0}\']/ScanMode[@type=\'{1}\']/SystemStatus\", product.ToString(), model.ToString());XmlNode node = m_docXml.SelectNodes(xPath)[0];String filePath = (node as XmlElement).InnerText;return filePath;}return \"\";}public static string GetSymInfoSystemMonitorStatusFilePath(Product product, ScanMode model){if (null != m_docXml){string xPath = string.Format(\"/PETGantrySimulator/Product[@type=\'{0}\']/SystemMonitorStatus\", product.ToString(), model.ToString());XmlNode node = m_docXml.SelectNodes(xPath)[0];String filePath = (node as XmlElement).InnerText;return filePath;}return \"\";}public static string GetSymInfoOverTempFilePath(Product product, ScanMode model){if (null != m_docXml){string xPath = string.Format(\"/PETGantrySimulator/Product[@type=\'{0}\']/OverTempStatus\", product.ToString(), model.ToString());XmlNode node = m_docXml.SelectNodes(xPath)[0];String filePath = (node as XmlElement).InnerText;return filePath;}return \"\";}public static string GetRawDataFilePathByProtocalKeyAndBedNo(Product product, string curProtocol, ScanMode model, int bedIndex){String filePath = \"\";try{if (null != m_docXml){string xPath = string.Format(\"/PETGantrySimulator/Product[@type=\'{0}\']/Protocols/Protocol[@type=\'{1}\']/RawData/Bed[@index=\'{2}\']\", product.ToString(), curProtocol.ToString(),  bedIndex.ToString());XmlNode node = m_docXml.SelectNodes(xPath)[0];filePath = (node as XmlElement).InnerText;}}catch (System.Exception ex){}return filePath;}}public enum Product{EXACTAPCT96 = 0,EXACTAPCT112 = 1,uMI510 = 2,uMI780A = 3,uMI780B = 4,uMI780C = 5,uMI780D = 6,uMI550 = 7,uMIX2000 = 8,uMI590 = 9,uMI880 = 10,uPMR790 = 11,uMIX500 = 12,uMI550M = 13,}public enum ScanMode{Coincidence,Single}}

		
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » xml文件读写(C#)