0

I have an Xelement being passed into a function:

ByVal request As XElement

inside the Xelement object is an element:

<nc:ID>1234567</nc:ID>

I should be able to get this value by:

request.Element("ID").value

...but it does not return anything. I suspect this is because of the namespace prefix. I saw a solution in this post which after translating to VB.net (request.Elements().Where(Function(e) e.Name.LocalName = "ID").Value) works, but I do not understand why or why the .element("ID").value does not return the value. Can anyone give me some insight into this?

Community
  • 1
  • 1
Popo
  • 2,402
  • 5
  • 33
  • 55
  • Have you tried using XmlReader, and XmlWriter? Or is that not an option? – Chase Ernst Aug 15 '13 at 19:09
  • @ChaseErnst My web service is consuming and returning Xelements so I was trying to use the methods associated with this object type. CreateReader will instantiate an xmlreader for the Xelement, but I think that is overkill since this object has simplified some of the tasks like getting an element value. – Popo Aug 15 '13 at 19:51

1 Answers1

0

I ran into the same problem today. Apparently "nc" is not the namespace, but is in fact the namespace prefix; you need to get the namespace itself. Here's how it turns out it has to be done:

XNamespace ns = request.GetNamespaceOfPrefix("nc");
XElement ID = request.Element(ns + "ID");