开发者

LINQ to XML Question: Returning Nodes with a particular select

I have this XML:

<?xml version="1.0" encoding="utf-8"?>

开发者_JAVA技巧

    <ConfiguraCanale ID_Comando="1">
        <canaleDigitalOUTPUT ID_Canale="1" >
            <stato>0</stato>
        </canaleDigitalOUTPUT>
    </ConfiguraCanale>


    <ConfiguraCanale ID_Comando="2">
        <canaleAnalogicoINPUT ID_Canale="2">                
            <timeAttesaPreCamp>00:03:00</timeAttesaPreCamp> 
        </canaleAnalogicoINPUT>
    </ConfiguraCanale>      

    </Comandi>

I must select the node canaleAnalogicoINPUT, and it's simple, but I must also take ID_Comando from ConfiguraCanale up to canaleAnalogicoINPUT.. because I select the node canaleAnalogicoINPUT I can't get attribute of the node ConfiguraCanale.

I use Linq to XML from few time...

Thanks!!!


It could be something like this:

var inputs = from e in doc.Descendants("canaleAnalogicoINPUT")
             select new
             {
                 CanaleAnalogicoINPUT = e, // extract what you need from this node
                 IDComando = int.Parse(e.Parent.Attribute("ID_Comando").Value)
             };


var inputs = from e in doc.Elements("ConfiguraCanale")
             select new 
             {
                 IDComando = e.Attribute("ID_Comando").Value,
                 CanaleAnalogicoINPUT = e.Element("canaleAnalogicoINPUT")
             };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜