Xml for CShape
2017年6月21日大约 2 分钟
拓展阅读
config 配置方式概览-8 种配置文件介绍对比 xml/json/proeprties/ini/yaml/TOML/hcl/hocon
config HCL(HashiCorp Configuration Language) 配置文件介绍
config HCL(HashiCorp Configuration Language) 官方文档翻译
config HOCON(Human-Optimized Config Object Notation)配置文件介绍
XStream java 实现 xml 与对象 pojo 之间的转换
java 实现 xml 与对象 pojo 之间的转换的几种方式 dom4j/xstream/jackson
YAML-02-yml 配置文件 java 整合使用 yamlbeans + snakeyaml + jackson-dataformat-yaml
XML
假设我们要解析形如 manifest.xml
的文件。
- manifest.xml
- XmlService.cs
///
/// 获取指定路径下,指定表明对应的数据
///
/// 文件路径
/// 对应表名
///
public static Dictionary GetFieldMapping(string filePath, string tableName)
{
Dictionary result = new Dictionary();
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlNode manifest = xmlDoc.SelectSingleNode("manifest");
XmlNode template = manifest.FirstChild;
foreach (XmlElement table in template)
{
string name = table.GetAttribute("name");
if (tableName.Equals(name))
{
foreach (XmlElement map in table)
{
string field = map.GetAttribute("field");
string posStr = map.GetAttribute("pos");
int pos = int.Parse(posStr);
result.Add(field, pos);
}
}
}
}
catch (Exception ex)
{
//throw ex;
return null;
}
return result;
}
- Main()
static void Main(string[] args)
{
string path = @"E:\CODE\xml\manifest.xml";
string tableName = "mdm.md_Bond";
Dictionary result = XmlService.GetFieldMapping(path, tableName);
foreach(string key in result.Keys)
{
Console.WriteLine(key + " "+ result[key]);
}
Console.ReadKey();
}
结果
UID 2
UniqueKey 3
LastUpdatedTime 4
贡献者
binbin.hou