Reading a specific property of an entity in XML with datajs results in error

Sep 22, 2011 at 9:22 AM

I am trying to read a specific property of an entity with XML format, similar to this url:

With the latest datajs 1.0.1, I get a "no handler for data" error.  I've debugged into datajs and the problem is at the dispatchHandler() function (line 4617 of datajs 1.0.1).

The dispatchHandler function looks through an array of handlers, trying to find a handler that will be able to handle the response.  The content-type of the url above ( is application/xml.  However, neither the atom handler nor the xml handler of datajs recognizes the element name (in the case of the url given, it is "Name").  In the case of the atom handler, it only seems to recognize "feed" and "entry" (at function readAtomDocument(), line 2381 of datajs).  In the case of the xml handler, it only recognize "links" and "uri" (you can see this code at the function readODataXmlDocument(), line 2021 of datajs).


If I request the url in json format, however, everything works correctly.  It's only XML that trips up datajs.


Is this a bug on datajs's part?  Or is this kind of operation not supported by datajs? 




Sep 22, 2011 at 9:43 AM

It appears DELETE and PUT operations that results in 204 No Content gives the same "no handler for data" error.  I suspect it is the same issue.  Is this something datajs will fix?

Sep 22, 2011 at 6:54 PM

Hi Jonathan,

    Hope you are doing great.  Indeed, reading and updating individual properties using the XML format is a feature we didn't include in the first version of datajs.   For now, the library only supports reading individual properties' raw value ($value).  We will consider adding support for this feature in the next version of the library.  For the time being, you can easily work around this limitation and update individual properties using a custom handler of your own.  For example, the following snippet will allow you to update an individual property raw value:

        requestUri: "$value",
        method: "PUT",
        headers: { "Content-Type": "text/plain" },
        data: "A new name"
    }, function success(data, response) {
        alert("response code: " + response.statusCode);
    }, function errorr(err) {
    }, {
        write: function (request) {
            if ( {
                request.body =;

 And later read the updated value again:"$value", function (data) { alert(data); });


Alex Trigo.

Sep 25, 2011 at 10:02 AM

Hi ATrigo, thanks for the workaround.  However, I really needed the XML to work because I am auto testing my OData service implementation using datajs.  I want to make sure the XML format being returned is correct.

The PUT/DELETE problem was easier to fix, what I would do is the following and it works well (in case anyone else ever encounters the same problem):

var deleteRequest = {
    method: "DELETE",
    requestUri: "http://myservice/entity"

OData.request(deleteRequest, undefined, function(err){
    if (err.response.statusCode == 204 &&
        err.response.body == ""){
    else {

Read the specific property with XML was harder.  I looked at how the Atom handler parsed the individual properties under the <m:properties> element and copied it to do the same for the XML handler.  Here is the modification I did:

    var readODataXmlDocument = function (xmlRoot) {
        /// <summary>Reads an OData link(s) producing an object model in return.</summary>
        /// <param name="xmlRoot">Top-level element to read.</param>
        /// <returns type="Object">The object model representing the specified element.</returns>

        if (xmlRoot.nsURI === odataXmlNs) {
            switch (xmlRoot.localName) {
                case "links":
                    return readLinks(xmlRoot);
                case "uri":
                    return readUri(xmlRoot);
            return readXmlProperty(xmlRoot);  //my modification
        return undefined;

    var readXmlProperty = function (property) {
        //I copied the implementation of this newly created function
        //from readAtomEntryProperty()
        var result = {};
        var propertyNullValue = null;
        var propertyTypeValue = "Edm.String";
        var propertyExtensions = [];

        xmlAttributes(property, function (attribute) {
            if (attribute.nsURI === odataMetaXmlNs) {
                switch (attribute.localName) {
                    case "null":
                        propertyNullValue = attribute.domNode.nodeValue;
                    case "type":
                        propertyTypeValue = attribute.domNode.nodeValue;

            if (isExtensionNs(attribute.nsURI)) {
                var extension = readAtomExtensionAttribute(attribute);

        var propertyValue = null;
        var propertyMetadata = {
            type: propertyTypeValue,
            extensions: propertyExtensions

        if (propertyNullValue !== "true") {
            propertyValue = xmlInnerText(property.domNode);
            if (isPrimitiveType(propertyTypeValue)) {
                propertyValue = convertFromAtomPropertyText(propertyValue, propertyTypeValue);
            } else {
                // Probe for a complex type and read it.
                if (xmlFirstElement(property)) {
                    propertyValue = { __metadata: { type: propertyTypeValue} };
                    readAtomEntryStructuralObject(property, propertyValue, propertyMetadata);

        result[property.localName] = propertyValue;

        return result;


What I did was instead of returning undefined when the XML root was neither "links" or "uri", I would treat the document as a specific xml property of an entity.  Seeing how the JSON handler does not seem to care what the type of the entity that the specific property belongs to is, I reasoned it would be ok to not care what the type of the entity of the XML specific property would be either.  The readXmlProperty function was a new function I created and mostly a copy and paste from the readAtomEntryProperty() function.

I tested it briefly and it seems to work ok.  If there are any problems with my implementation please feel free to let me know.  For now it'll serve as my quick hack to get this to work before you guys officially support reading specific properties in XML format.