tags:

views:

83

answers:

2
+2  A: 

Unfortunately the implicit conversion from string to XName does not parse out the namespace. You need to do this:

XName.Get("foobar", "asdf");
ChaosPandion
`XName.Get("foobar", "asdf").ToString()` returns `{asdf}foobar`, which seems like what I want but is not working out right now. I'll double-check my code for subtle errors and report back.
adam_0
The "asdf" bit is called a namespace. Somewhere above that element in the tree there will be an attribute like `xmlns:asdf="http://www.example.com/whatever"`. It's actually the "http://www.example.com/whatever" that you need to pass as the second parameter to `XName.Get` - "asdf" is just an alias, "http://www.example.com/whatever" is the actual namespace.
Dean Harding
So the result should be a string like `{http://www.example.com/whatever}foobar`?
adam_0
Something that I just noticed is that the `xmlns:asdf="http://www.example.com/whatever` part is on the same line as the `<asdf:foobar>` line... might that affect the result?
adam_0
No, `xmlns:...="..."` applies to this element and any under it.
Porges
+1  A: 

Another way you can handle namespaces is by using the XNamespace class.

  XNamespace ns = "http://www.example.com/whatever";
  XElement child = new XElement(ns + "base");
mdm20