xml文件解析
如何添加/更改我的代码,以便一旦提取出最大/最小值的值,它将提取的值与设定值进行比较并写出通过/失败。例如:xmax 提取出来,它是 280,我的代码中有一个条件说 xmax 需要小于 275,所以写出失败。这需要为每个最大/最小完成。有什么想法......?我使用 linq to xml 进行解析,但它们是更好的方法吗?
var query = from file in fileEntries
let doc = XDocument.Load(file)
let x = doc.Descendants("XAxisCalib").Single()
let y = doc.Descendants("YAxisCalib").Single()
let z = doc.Descendants("ZAxisCalib").Single()
select new
{
XMax = x.Element("Max").Value,
XMin = x.Element("Min").Value,
YMax = y.Element("Max").Value,
YMin = y.Element("Min").Value,
ZMax = z.Element("Max").Value,
ZMin = z.Element("Min").Value
};
How can I add/alter to my code so once if extracts out the values of the max/min it compare the extracted value to a set value and writes out pass/fail. For example: xmax extracts out and it is 280 and I have a condition in my code saying that xmax needs to be less than 275 so write out fail. This needs to be done for each max/min.Any Ideas...? I used linq to xml to parse but is their a better way?
var query = from file in fileEntries
let doc = XDocument.Load(file)
let x = doc.Descendants("XAxisCalib").Single()
let y = doc.Descendants("YAxisCalib").Single()
let z = doc.Descendants("ZAxisCalib").Single()
select new
{
XMax = x.Element("Max").Value,
XMin = x.Element("Min").Value,
YMax = y.Element("Max").Value,
YMin = y.Element("Min").Value,
ZMax = z.Element("Max").Value,
ZMin = z.Element("Min").Value
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许是这样的?
Something like this maybe?
我将为此使用 XML 模式。
它将允许您构建 C#,这样只需几行代码即可检查文档的结构正确性和语义正确性。您也可以将其与应用程序分开发布,以便用户可以了解文档的布局方式。一些 XML 编辑器也支持模式,因此它们可能会在编辑器中获得某种自动语法支持/检查。
以下是检查 XSD 架构中最大值的方法:
http://www.w3schools.com /schema/schema_facets.asp
I'd use an XML schema for this.
It will let you build your C# so that it takes just a few lines of code to check the document both for structural correctness, and semantic correctness. It is also something you can publish separately from your app so that users can understand how documents should be laid out. Some XML editors support schemas, too, so they might get some sort of automatic syntactical support/checking in their editor.
Here is how you would check a maximum value in an XSD schema:
http://www.w3schools.com/schema/schema_facets.asp
您可以创建一个扩展方法来检查值
然后您可以执行以下操作
You can create an Extension Method to check the value
Then you can do