The little ‘gotcha’ in LINQ to XML(geekdaily.net)

submitted by justinbezansonjustinbezanson(1555) 3 years, 6 months ago

So when my query kept returning 0 elements I started to get frustrated. Why wasn’t it working?

3 comments |category: |Views: 15

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by jmferrisjmferris(85) 3 years, 6 months ago 0

The namespace handling in LINQ to XML is a drop-dead awesome feature. I have only used in in VB.NET, but if the namespace that you are using is known to you ahead of time, you can simply import it.

Imports <xmlns:ns="http://namespaceUri">

A quick Google for "LINQ to XML Namespaces" brought this up as the second result on the first page:
http://msdn.microsoft.com/en-us/library/bb384460.aspx

You can additionally navigate using the full node name, including the namespace.

Reply

posted by justinbezansonjustinbezanson(1555) 3 years, 6 months ago 0

@jmferris, thanks for your input. Your suggestion works great for VB, unforetunately I am using C# and C# does not support importing namespaces. The C# solution is not as clean but it doable. http://msdn.microsoft.com/en-us/library/system.xml.linq.xnamespace.aspx.

thanks again.

Reply

posted by jmferrisjmferris(85) 3 years, 6 months ago 0

@justin, you should be able to switch the Imports to a using for C#. I haven't personally tried it, but I am see a few people on EggheadCafe saying that it works - although it is not documented in the C# documentation.

Best of luck!

Reply

information Login or create an account to comment on this story