Traversing XML with Linq to XML - newbie q

S

Simon Woods

Hi

I am struggling to navigate an XElement and I'm not sure what is going
wrong. Here's my XML via vb's xml literals

Dim l_testSchema = _
<Mappings>
<Definitions>
<ItemGroup>
<Parent>Table</Parent>
<Name>Name</Name>
</ItemGroup>
<Item>
<Parent>Column</Parent>
<Name>Name</Name>
<Type>Type</Type>
</Item>
</Definitions>

<Data>
<Table>
<Name>MyTable</Name>
<Columns>
<Column>
<Name>MyColumn1</Name>
<Type>String</Type>
</Column>
<Column>
<Name>MyColumn2</Name>
</Column>
<Column>
<Name>MyColumn3</Name>
</Column>
<Column>
<Name>MyColumn4</Name>
</Column>
<Column>
<Name>MyColumn5</Name>
</Column>
<Column>
<Name>MyColumn6</Name>
</Column>
</Columns>
</Table>
</Data>
</Mappings>

I'm basically wanting to use linq to traverse this but I'm struggling to
get anything back

e.g.
l_testSchema.Elements("Columns").Count returns 0
l_testSchema.Descendents(Columns").Count returns 1

In fact I'm struggling to get any other result other than 0 or 1.

Why is that the case? What am I missing?

Thx

Simon
 
S

Simon Woods

OK ... I didn't realise I needed to put in the absolute path

l_testSchema.Element("Data").Element("Table").Element("Columns").Elements.Count

I thought it would just 'jump' to the correct element.

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top