【发布时间】:2014-06-25 10:55:12
【问题描述】:
我有以下 XML
<departments>
<dept operationalStatus="active" primaryRole="Admin" depChangeDate="20130420">
<startDate type="legal">20130401</startDate>
<endDate type="legal"></endDate>
<startDate type="operational">20130320</startDate>
<endDate type="operational"></endDate>
<DeptRoles>
<DeptRole name="Other dept" status="active">
<startDate type="legal">20130401</startDate>
<endDate type="legal"></endDate>
<startDate type="operational">20130320</startDate>
<endDate type="operational"/>
<isPrimary/>
</DeptRole>
</DeptRoles>
</dept>
</departments>
我有大约 200K 记录要从 xml 文件上传到数据库。我想从一张表中的 xml 文件中获取以下数据 operationStatus、primaryRole、depChangeDate、startDate 类型合法及其值和 startDate 类型可操作及其值 我可以访问 startDate 类型的合法元素,但无法访问 startDate 类型的操作。 并将 DeptRole 元素中的以下数据放入另一个表中。 DeptRole 名称、状态、startDate 类型合法及其值和 startDate 类型可操作及其值。 什么是最好的方法,我该怎么做。 主要是我在访问以下值时遇到问题
<startDate type="legal">20130401</startDate>
<endDate type="legal"></endDate>
<startDate type="operational">20130320</startDate>
<endDate type="operational"></endDate>
【问题讨论】:
-
您是如何尝试访问这些值的?
-
@DanielKelley by if (el.Element("startDate").Attribute("type").ToString() == "legal"
-
@DanielKelley if (el.Element("startDate").Attribute("type").ToString() == "operational"
-
@DanielKelley 法律价值是成功的,但如果声明永远不正确则可操作
标签: c# sql-server xml linq-to-xml