【发布时间】:2014-01-21 17:05:14
【问题描述】:
作为项目的一部分,我需要从一些似乎不是标准 XML 的 XML 中解析一些值。 XML 存储在 SQL Server 中。我需要查询数据库并检索此 XML,然后在 C# 中我需要获取 XCoord 和 YCoord 字段的值。有人可以告诉我如何使用 System.Xml 来实现吗?
如果有人知道通过 SQL 查询从 XML 数据中返回这些值,那也可以。
<AdapterItem xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.enceladus.com/Data">
<Attributes>
<Attribute>
<Name>Process ID</Name>
<Value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">1000</Value>
</Attribute>
<Attribute>
<Name>Request</Name>
<Value i:type="AdapterItem">
<Attributes>
<Attribute>
<Name>Location</Name>
<Value i:type="AdapterItem">
<Attributes>
<Attribute>
<Name>XCoord</Name>
<Value xmlns:d10p1="http://www.w3.org/2001/XMLSchema" i:type="d10p1:string">482557.53208923</Value>
</Attribute>
<Attribute>
<Name>YCoord</Name>
<Value xmlns:d10p1="http://www.w3.org/2001/XMLSchema" i:type="d10p1:string">240588.72462463</Value>
</Attribute>
</Attributes>
</Value>
</Attribute>
<Attribute>
<Name>Description</Name>
<Value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">Some Description</Value>
</Attribute>
</Attributes>
</Value>
</Attribute>
</Attributes>
</AdapterItem>
提前致谢!
【问题讨论】:
-
“非标准”是指“格式不正确且无法解析”吗?
-
XML 格式良好,但我不熟悉它的布局。您可以说
000.000 但我意识到该值需要其自身的其他属性,例如“类型”。 -
感谢您的澄清。我认为最好不要说“非标准”,因为它可能具有误导性。但很高兴你得到了答案,无论如何!
-
当然可以。这是个误会。
-
不用担心。祝你有美好的一天。