score:2

Accepted answer

you are trying to select response elements from response element (which is root of your xml). use this element directly instead:

var responseelement = xelement.load(path_to_xml);
var statuselement = responseelement.element("status");
var myobject = new marketclockresponse
{
    response = new response
    {
        id = (string)responseelement.attribute("id"),
        date = (string)responseelement.element("date"),
        message = (string)responseelement.element("message"),
        status = new status
        {
            current = (string)statuselement.element("current"),
            change_at = (string)statuselement.element("change_at")
        }
    }
};

score:1

var myobject = xelem.descendants("response").select(
        x => new marketclockresponse
        {
              response = new response
             {
                id = x.attribute("id").value,
                //.....
                //populate all the attributes
             }
        });

score:1

first of all, i would use xdocument.load instead of xelement.load, because your xml is a document, with declaration, etc.

var xdoc = xdocument.load("input.txt");

then, i'd set two local variables to avoid querying for the same thing more than once:

var resp = xdoc.root;
var status = resp.element("status");

and use them to get what you need:

var myobject = new marketclockresponse
{
    response = new response
    {
        id = (string)resp.attribute("id"),
        date = (string)resp.element("date"),
        message = (string)resp.element("message"),
        status = new status
        {
            current = (string)status.element("current"),
            change_at = (string)status.element("change_at")
        }
    }
};

Related Query

More Query from same tag