本文介绍了如何获取XML标记ID和文件标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是 我的xml文件
<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>
< QUERIES>
< SQL ID =" Sheet1">
<! -
select * from file1
- >
< / SQL>
< SQL ID =" Sheet2">
<! - select * from file2
- >
< / SQL>
< SQL ID =" Sheet3">
<! - select * from file3
- >
< / SQL>
< FILE> CUSTOMER< / FILE>
< / QUERIES>
XDocument xml1 = XDocument.Load(System.IO.Path.GetDirectoryName(System.Reflection) .Assembly.GetEntryAssembly()。Location)+" \\Sql.xml");
List< string> sql_strings1 =((IEnumerable< object>)xml1.XPathEvaluate(" / * / SQL / comment()"))
.Cast< XComment>()
.Select(c => c .Value.Trim())
.ToList();
如何在lis< string>中获取值ID sheet1,sheet2,sheet3 可变&NBSP;来自Xdocument xml1。另外,我如何获得标签名称 < FILE> CUSTOMER< / FILE>在字符串变量
请帮助
polachan
解决方案
This is my xml file
<?xml version="1.0" encoding="utf-8" ?> <QUERIES> <SQL ID="Sheet1"> <!-- select * from file1 --> </SQL> <SQL ID="Sheet2"> <!-- select * from file2 --> </SQL> <SQL ID="Sheet3"> <!-- select * from file3 --> </SQL> <FILE>CUSTOMER</FILE> </QUERIES>
XDocument xml1 = XDocument.Load(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) +"\\Sql.xml"); List<string> sql_strings1 = ((IEnumerable<object>)xml1.XPathEvaluate("/*/SQL/comment()")) .Cast<XComment>() .Select(c => c.Value.Trim()) .ToList();
How can I get the value ID sheet1, sheet2, sheet3 in a lis<string> variable from Xdocument xml1. Also How can I get the tag name <FILE>CUSTOMER</FILE> in string variable
Please help
polachan
解决方案
这篇关于如何获取XML标记ID和文件标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!