NAN_METHOD(XmlDocument::Encoding)
{
    Nan::HandleScope scope;
    XmlDocument* document = Nan::ObjectWrap::Unwrap<XmlDocument>(info.Holder());
    assert(document);

    // if no args, get the encoding
    if (info.Length() == 0 || info[0]->IsUndefined()) {
        if (document->xml_obj->encoding)
            return info.GetReturnValue().Set(Nan::New<v8::String>(
                        (const char *)document->xml_obj->encoding,
                        xmlStrlen((const xmlChar*)document->xml_obj->encoding)).ToLocalChecked());

        return info.GetReturnValue().Set(Nan::Null());
    }

    // set the encoding otherwise
    Nan::Utf8String encoding(Nan::To<v8::String>(info[0]).ToLocalChecked());
    if(document->xml_obj->encoding != NULL) {
        xmlFree((xmlChar*)document->xml_obj->encoding);
    }

    document->xml_obj->encoding = xmlStrdup((const xmlChar*)*encoding);
    return info.GetReturnValue().Set(info.Holder());
}
NAN_METHOD(XmlDocument::Encoding)
{
    Nan::HandleScope scope;
    XmlDocument* document = Nan::ObjectWrap::Unwrap<XmlDocument>(info.Holder());
    assert(document);

     
    if (info.Length() == 0 || info[0]->IsUndefined()) {
        if (document->xml_obj->encoding)
            return info.GetReturnValue().Set(Nan::New<v8::String>(
                        (const char *)document->xml_obj->encoding,
                        xmlStrlen((const xmlChar*)document->xml_obj->encoding)).ToLocalChecked());

        return info.GetReturnValue().Set(Nan::Null());
    }

     
    Nan::Utf8String encoding(Nan::To<v8::String>(info[0]).ToLocalChecked());
    if(document->xml_obj->encoding != NULL) {
        xmlFree((xmlChar*)document->xml_obj->encoding);
    }

    document->xml_obj->encoding = xmlStrdup((const xmlChar*)*encoding);
    return info.GetReturnValue().Set(info.Holder());
}