How can I grab user name from XML via LINQ to XML?

The part in front of the colon is a namespace, knowing this I found this answer from a similar question Linq to XML with Namespace.

The part in front of the colon is a namespace, knowing this I found this answer from a similar question. Linq to XML with Namespace.

Several people had a useful answer but this was the first (according to the "oldest" sort) so it got the answer. All of them got +1. – Sailing Judo Sep 7 '10 at 19:20.

You need to create a namespace and use that. It's highly counter intuitive, but this is how it works: XNamespace ns = "schemas.xmlsoap.org/soap/envelope/"; from item in xdoc. Descendants(ns + "UsernameToken") ...etc... ...and you'll have to do that for any item that has a prefix.

I think you can also use curly braces ({}) as a wrapper around the URI, like this: from item in xdoc. Descendants("{schemas.xmlsoap.org/soap/envelope/}Usern...) but I've never tried it. More details here.

It's down to the namespaces for those xml elements. You need to add that to your query. I'm not at a point to try this but something along the lines of: XNamespace wsu = "docs.oasis-open.org/wss/2004/01/oasis-20...; var xdoc = XDocument.

Parse(xml, LoadOptions. None); var userName = from item in xdoc. Descendants(wsu + "UsernameToken") select new { UserName = item.

Element(wsu + "UserName") }; For more information on namespaces in LINQ to XML: http://msdn.microsoft.com/en-us/library/bb387069.aspx.

You have to include the whole namespace in the LINQ: XNamespace wsse = "docs.oasis-open.org/wss/2004/01/oasis-20...; var xdoc = XDocument. Parse(xml, LoadOptions. None); var userName = from item in xdoc.

Descendants(wsse + "UsernameToken") select new { UserName = item. Element(wsse + "UserName") }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions