vb.net triple dot syntax for linq to xml
I ran into this answer which had a triple dot syntax in VB.NET that I have never seen before.
The query looks like this
Dim result =
From xcmp In azm...<Item>.<ItemPrice>开发者_JAVA百科;.<Component>
Where xcmp.<Type>.Value = "Principal"
Select Convert.ToDecimal(xcmp.<Amount>.Value)
I tried to search on google about this triple dot syntax but I didn't get anything.
Can someone point to to some documentation about this syntax and I was also wondering it will work with C# or if there is an equivalent ?
Thanks
When using ... instead of ., you refer not to the direct child <Item>
, but to any <Item>
in the hierarchy tree.
So <A>...<B>
give a result for
<A>
<X1>
<X2>
<B></B>
</X2>
</X1>
</A>
whereas <A>.<B>
would give no result in this example...
The triple dots is a “descendant axis” which is used to access a list of XML nodes of a given name in XML literal syntax (“LINQ to XML”):
Gets all name elements of the [parent] element, regardless of how deep in the hierarchy they occur.
This syntax doesn’t exist in C#, only in VB (for the moment).
The answer you're referring to was mine from another question, and the triple dot is just a shortcut for calling .Descendants()
. C# doesn't support inline XML, so you'll have to call the methods unless you're in VB. Here's the mapping:
- VB.NET shortcut := C# method
...<node>
:=.Descendants("node")
.<node>
:=.Elements("node")
.@attr
:=.Attribute("attr").Value
You can see all of these from VB's intellisense.
精彩评论