I have an xml file that contains its element like
<ab:test>Str</ab:test>
When I am trying to access it using the code:
XElement tempElement = doc.Descendants(XName.Get("ab:test")).FirstOrDefault();
It's giving me this error:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name.
How should I access it?
If you want to use namespaces, LINQ to XML makes that really easy:
Look for an
xmlns:ab=...
section in your document to find out which namespace URI "ab" refers to.I was having the same error. I found I was adding code...
... but ab was determined to be a string. This caused the error reported by OP. Instead of using the VAR keyword, I used the actual data type XNamespace...
... and the problem went away.
Try putting your namespace in
{
...}
like so:There is an overload of the Get method you might want to try that takes into account the namespace. Try this:
Try to get namespace from the document