xmlns=''> was not expected. - There is an error in XML document (2, 2)

xmlns:xsi
xmlns:svg
xmlns attribute
xmlns:ns
xmlns=urn
xmlns:h
xmlns:ns1
xmlns:m

Im trying to deserialize the response from this simple web service

Im using the following code:

WebRequest request = WebRequest.Create("http://inb374.jelastic.tsukaeru.net:8080/VodafoneDB/webresources/vodafone/04111111");    
WebResponse ws = request.GetResponse();
XmlSerializer s = new XmlSerializer(typeof(string));
string reponse = (string)s.Deserialize(ws.GetResponseStream());

Declaring XmlSerializer as

XmlSerializer s = new XmlSerializer(typeof(string),new XmlRootAttribute("response"));

is enough.

HTML html xmlns Attribute, The prefix xmlns is used only to declare namespace bindings and is by definition bound to the namespace name http://www.w3.org/2000/xmlns/ . The xmlns attribute specifies the xml namespace for a document. Note: The xmlns attribute is required in XHTML, invalid in HTML 4.01, and optional in HTML5.


You want to deserialize the XML and treat it as a fragment.

There's a very straightforward workaround available here. I've modified it for your scenario:

var webRequest = WebRequest.Create("http://inb374.jelastic.tsukaeru.net:8080/VodafoneDB/webresources/vodafone/04111111");

using (var webResponse = webRequest.GetResponse())
using (var responseStream = webResponse.GetResponseStream())
{
    var rootAttribute = new XmlRootAttribute();
    rootAttribute.ElementName = "response";
    rootAttribute.IsNullable = true;

    var xmlSerializer = new XmlSerializer(typeof (string), rootAttribute);
    var response = (string) xmlSerializer.Deserialize(responseStream);
}

Namespaces in XML 1.0 (Third Edition), XML namespaces are used for providing uniquely named elements and attributes in an XML An XML namespace is declared using the reserved XML attribute xmlns or xmlns:prefix , the value of which must be a valid namespace name. As attribute nodes named "xmlns" or "xmlns:xxx", exactly as the namespaces are written in the source XML document. This is the model presented by DOM. As namespace declarations: distinguished from attributes, but corresponding one-to-one with the relevant attributes in the source XML document. This is the model presented by JDOM.


I had the same error with Deserialize "xml string with 2 namespaces declared" into object.

<?xml version="1.0" encoding="utf-8"?>
<vcs-device:errorNotification xmlns:vcs-pos="http://abc" xmlns:vcs-device="http://def">
    <errorText>Can't get PAN</errorText>
</vcs-device:errorNotification>
[XmlRoot(ElementName = "errorNotification", Namespace = "http://def")]
public class ErrorNotification
{
    [XmlAttribute(AttributeName = "vcs-pos", Namespace = "http://www.w3.org/2000/xmlns/")]
    public string VcsPosNamespace { get; set; }

    [XmlAttribute(AttributeName = "vcs-device", Namespace = "http://www.w3.org/2000/xmlns/")]
    public string VcsDeviceNamespace { get; set; }

    [XmlElement(ElementName = "errorText", Namespace = "")]
    public string ErrorText { get; set; }
}

By adding field with [XmlAttribute] into ErrorNotification class deserialization works.

public static T Deserialize<T>(string xml)
{
    var serializer = new XmlSerializer(typeof(T));
    using (TextReader reader = new StringReader(xml))
    {
        return (T)serializer.Deserialize(reader);
    }
}

var obj = Deserialize<ErrorNotification>(xml);

XML namespace, The xmlns attribute declares an XML Namespace. The Namespaces in XML standard discusses this element in depth. Namespaces are used� In the attribute xmlns:pfx, xmlns is like a reserved word, which is used only to declare a namespace. In other words, xmlns is used for binding namespaces, and is not itself bound to any namespace. In other words, xmlns is used for binding namespaces, and is not itself bound to any namespace.


what is the exact usage of xmlns in xml, and html, The Namespace starts with the keyword xmlns. The word name is the Namespace prefix. The URL is the Namespace identifier. Example. Namespace affects only� A Namespace is declared using reserved attributes. Such an attribute name must either be xmlns or begin with xmlns: shown as below − <element xmlns:name = "URL"> Syntax. The Namespace starts with the keyword xmlns. The word name is the Namespace prefix. The URL is the Namespace identifier. Example. Namespace affects only a limited area in the


XML - Namespaces, Associates a namespace prefix with a XML namespace URI. Usage. @XmlNs annotation is intended for use from other program annotations. See "Package� Test Run. That’s it, now you can add a test component to see if everything is ok.


XmlNs (Java Platform SE 8 ), In the attribute xmlns:pfx, xmlns is like a reserved word, which is used only to declare a namespace. In other words, xmlns is used for binding namespaces, and�