如何解析具有相同名称但没有属性的Xelemnts? [英] how parse xelemnts that have the same name but hasn'l attributes?

查看:80
本文介绍了如何解析具有相同名称但没有属性的Xelemnts?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载数据并将其保存到数据库,但是在某些情况下,我现在所拥有的就是文件包含的许多元素,其中某些元素的属性值具有不同的值,而另一些则没有.

I trying to load data and save to a database but some case what I have now is what the file contains many elements some have attributes with different value  and others no.

当加载数据时,加载所有元素并达到4000甚至更多,我得到一个例外,这就是解释这一行的原因

And when load the data loads all elements and reach the 4000 and more i gets a exception what explain this the line is this

translation = string.Join<string>(", ", from t in element.Descendants("gloss") select t.Value))

我现在想返回所有没有属性的

I want return all with hasn't attributes for now

另一个是什么时候我加载了具有指定属性的元素,但是许多根元素没有具有属性I的特定元素,但又出现了另一个异常,不允许我继续.

Another one is when  I load elements what has specified attributes but many of the root elements hasn't that specific element with attribute I gets another exception what don't let me continue.

此行.

esTranslation = from es in element.Descentdants("gloss") where (x => !string.IsNullOrEmpty(es.Atteibute("xml_Lang").Value == "spa" )) select es.Value

 我如何跳过这些不包含属性的元素,并存储它们具有的属性?

 how can I skip these elements what do not contains the attribute and store they what has?

推荐答案

我认为您有错别字,请尝试以下代码相反:

i think you have typos, please try this code instead:

esTranslation = from es in element.Descendants("gloss") where (x => !string.IsNullOrEmpty(es.Attribute("xml_Lang").Value == "spa" )) select es.Value

希望这会有所帮助!


这篇关于如何解析具有相同名称但没有属性的Xelemnts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆