473,659 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Colum n</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.El ements("Columns ").Count returns 0
l_testSchema.De scendents(Colum ns").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 2755
OK ... I didn't realise I needed to put in the absolute path

l_testSchema.El ement("Data").E lement("Table") .Element("Colum ns").Elements.C ount

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>Colum n</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.El ements("Columns ").Count returns 0
l_testSchema.De scendents(Colum ns").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.De scendants("Colu mn").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>Colum n</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.El ements("Columns ").Count returns 0
l_testSchema.De scendents(Colum ns").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
4868
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 next for null).Is there any way to find the length of linked list in c.My need is to traverse from the end to 5th node Regards, Mani
2
1306
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. I tried the following query var results = from e in emp.employee where e.employeeRowParent.name == "Doe" select e;
30
4271
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
1523
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 query. The query comes from a table which picks values from another table. When I try traversing the query through TAB button, I get the following warning - "The value you entered isnt valid for this field. For example you might have entered a text...
3
1080
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 \microsoft sql server\mssql\data\northwnd.mdf"); Table<CustomerCustomers = db.GetTable<Customer>(); var query = from cust in Customers where cust.City == "London" select cust; foreach (var cust in query) Console.WriteLine(string.Format("id = {0}, City =
10
1203
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, "Bundaberg")); Persons.Add(new Person("Cathryn", 36, "Perth"));
5
1152
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 productGroups = from p in products group p by p.Category into g where g.Group.Any(p =p.UnitsInStock == 0) select new { Category = g.Key, Products = g.Group };
2
1203
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> <Parent>Table</Parent>
0
1072
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 (think about creating a sql report); I would like to save and reload the query, and I'm trying to implement it as a LINQ query. Is there any way to do this? Thanks,
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.