c#读取xml文件属性
xml文件:<?xmlversion="1.0"encoding="utf-8"?><Documentxmlns:xsi="http://www.w3.org/2001/...
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="终端接口XML Schema-2.0.xsd" SN="343617" License="040">
<Events>
<!--销售出库,-->
<Event Name="SalesWareHouseOut" MainAction="WareHouseOut">
<ActionMaping>
<Action Name="WareHouseOut">
<ActionData>Code</ActionData>
<ActionData>CorpOrderID</ActionData>
<ActionData>Actor</ActionData>
<ActionData>ActDate</ActionData>
</Action>
</ActionMaping>
<DataMaping>
<MetaData Name="Code" Type="string" />
<MetaData Name="CorpOrderID" Type="string" />
<MetaData Name="Actor" Type="string" />
<MetaData Name="ActDate" Type="Date" />
</DataMaping>
<DataField>
<Data Code="81143900028040251957" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027511806124" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027510453880" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027509255484" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027508057635" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027508204343" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027509403677" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027510601766" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027511950686" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900028040405694" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
</DataField>
</Event>
</Events>
</Document>
只要读取全部CorpOrderID即可 展开
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="终端接口XML Schema-2.0.xsd" SN="343617" License="040">
<Events>
<!--销售出库,-->
<Event Name="SalesWareHouseOut" MainAction="WareHouseOut">
<ActionMaping>
<Action Name="WareHouseOut">
<ActionData>Code</ActionData>
<ActionData>CorpOrderID</ActionData>
<ActionData>Actor</ActionData>
<ActionData>ActDate</ActionData>
</Action>
</ActionMaping>
<DataMaping>
<MetaData Name="Code" Type="string" />
<MetaData Name="CorpOrderID" Type="string" />
<MetaData Name="Actor" Type="string" />
<MetaData Name="ActDate" Type="Date" />
</DataMaping>
<DataField>
<Data Code="81143900028040251957" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027511806124" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027510453880" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027509255484" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027508057635" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027508204343" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027509403677" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027510601766" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900027511950686" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
<Data Code="81143900028040405694" ReplaceCode="" CorpOrderID="138204" Actor="1" ActDate="2013-12-19 08:47:09" WrongCode="" UpperCorpOrderID="" />
</DataField>
</Event>
</Events>
</Document>
只要读取全部CorpOrderID即可 展开
2个回答
展开全部
string xmlPath = Server.MapPath("~/xmlTest.xml");
XDocument xd = XDocument.Load(xmlPath);
var temp = (from x in xd.Descendants("Data")
select new
{
CorpOrderID = x.Attribute("CorpOrderID").Value
}).ToList();
foreach (var item in temp)
{
litMsg.Text += item.CorpOrderID + "<br/>";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System.Xml.Linq;
XElement xml = XElement.Load(@"D:\Test\user.xml");
var query = xml.Descendants("Data");
foreach (var item in query)
{
Console.WriteLine(item.Attribute("CorpOrderID").Value);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询