473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Traversing XML with Linq to XML - newbie q

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
Oct 30 '08 #1
2 2747
OK ... I didn't realise I needed to put in the absolute path

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

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

Thx

Simon Woods wrote:
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
Oct 30 '08 #2


l_testSchema.Descendants("Column").Count gives me what I was after.

Thx
Simon Woods wrote:
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

Oct 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
2
by: Satish | last post by:
Hi I an newbie to LINQ. I have a dataset with one table employee which has a self referencing foreign key manger id. I want to write a query to get all the employees under a particular manager....
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
by: somcool | last post by:
I am facing an error while traversing a query in MS Access Details - When I click a button, a form which has the query opens up. There are certain fields which are in the form of combo box in the...
3
by: zacks | last post by:
I am trying to get into LINQ. I have created ConsoleApplication project and have pasted in the code from one of the examples in help: DataContext db = new DataContext(@"c:\program files...
10
by: damiensawyer | last post by:
Hi, I have the following code extract... ---top--- List<PersonPersons = new List<Person>(); Persons.Add(new Person("Peter", 28,"Perth")); Persons.Add(new Person("Matthew", 31,...
5
by: Mike P | last post by:
Here is another one I hope somebody can help me with, this is the AnyGrouped example and does not recognise the 'Group' as being valid : List<Productproducts = GetProductList(); var...
2
by: Simon Woods | last post by:
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>...
0
by: balint kardos | last post by:
Hi all, My question is about parsing and saving a LINQ query from/to xml. I'm creating an web interface where a user can select fields from dataset tables, and create relations between them...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.