473,569 Members | 2,598 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 1201
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
4865
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
1303
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
4256
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
1522
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...
3
1076
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 ==...
10
1199
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
1142
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...
1
2589
by: DaveD | last post by:
Let's say I have a collection ("items") of objects that each have a "string Name" property. I understand I can create a loop like this: foreach (string name in names) { var item = (from x in items where name == x.Name select x).First(); // Work on item } Is there a way to make that query more efficient? (My assumption is
2
2752
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
1069
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...
0
7700
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...
0
8125
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...
1
7676
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...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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...

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.