If KeyLocator is a KeyName, allow the key name data to be omitted.
diff --git a/ndn-cpp/c/encoding/binary-xml-key.c b/ndn-cpp/c/encoding/binary-xml-key.c
index 42e4463..1f61e51 100644
--- a/ndn-cpp/c/encoding/binary-xml-key.c
+++ b/ndn-cpp/c/encoding/binary-xml-key.c
@@ -47,8 +47,11 @@
               (decoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, 0, &keyLocator->keyData, &keyLocator->keyDataLength)))
             return error;
         }
-        else
-          return NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type;
+        else {
+          // Key name data is omitted.
+          keyLocator->keyNameType = -1;
+          keyLocator->keyDataLength = 0;
+        }
       }
     }
   }
@@ -81,29 +84,31 @@
     if ((error = ndn_encodeBinaryXmlName(&keyLocator->keyName, encoder)))
       return error;
     
-    if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST) {
-      if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
-          (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, keyLocator->keyData, keyLocator->keyDataLength)))
-        return error;    
+    if ((int)keyLocator->keyNameType >= 0 && keyLocator->keyDataLength > 0) {
+      if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST) {
+        if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+            (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+          return error;    
+      }
+      else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST) {
+        if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+            (encoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+          return error;    
+      }
+      else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST) {
+        if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+            (encoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+          return error;    
+      }
+      else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST) {
+        if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+            (encoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+          return error;    
+      }
+      else
+        return NDN_ERROR_unrecognized_ndn_KeyNameType;
     }
-    else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST) {
-      if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
-          (encoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, keyLocator->keyData, keyLocator->keyDataLength)))
-        return error;    
-    }
-    else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST) {
-      if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
-          (encoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, keyLocator->keyData, keyLocator->keyDataLength)))
-        return error;    
-    }
-    else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST) {
-      if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
-          (encoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, keyLocator->keyData, keyLocator->keyDataLength)))
-        return error;    
-    }
-    else
-      return NDN_ERROR_unrecognized_ndn_KeyNameType;
-
+    
     if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
       return error;
   }
diff --git a/ndn-cpp/c/errors.c b/ndn-cpp/c/errors.c
index af70f56..7f87c5b 100644
--- a/ndn-cpp/c/errors.c
+++ b/ndn-cpp/c/errors.c
@@ -56,8 +56,6 @@
     return      "unrecognized ndn_KeyNameType";
   case NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type:
     return      "decodeBinaryXmlKeyLocator unrecognized key locator type";
-  case NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type:
-    return      "decodeBinaryXmlKeyLocator unrecognized key name type";
   case NDN_ERROR_unrecognized_ndn_SocketTransport:
     return      "unrecognized ndn_SocketTransport";
   case NDN_ERROR_SocketTransport_error_in_getaddrinfo:
diff --git a/ndn-cpp/c/errors.h b/ndn-cpp/c/errors.h
index da8548f..ee76528 100644
--- a/ndn-cpp/c/errors.h
+++ b/ndn-cpp/c/errors.h
@@ -36,7 +36,6 @@
   NDN_ERROR_unrecognized_ndn_KeyLocatorType,
   NDN_ERROR_unrecognized_ndn_KeyNameType,
   NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type,
-  NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type,
   NDN_ERROR_unrecognized_ndn_SocketTransport,
   NDN_ERROR_SocketTransport_error_in_getaddrinfo,
   NDN_ERROR_SocketTransport_cannot_connect_to_socket,
diff --git a/ndn-cpp/c/key.h b/ndn-cpp/c/key.h
index 5bfe05e..f6df357 100644
--- a/ndn-cpp/c/key.h
+++ b/ndn-cpp/c/key.h
@@ -40,7 +40,7 @@
     */
   unsigned int keyDataLength;  /**< The length of keyData. */
   struct ndn_Name keyName;     /**< The key name (only used if type is ndn_KeyLocatorType_KEYNAME.) */
-  ndn_KeyNameType keyNameType; /**< The type of data for keyName (only used if type is ndn_KeyLocatorType_KEYNAME.) */
+  ndn_KeyNameType keyNameType; /**< The type of data for keyName, -1 for none. (only used if type is ndn_KeyLocatorType_KEYNAME.) */
 };
 
 /**
diff --git a/ndn-cpp/key.hpp b/ndn-cpp/key.hpp
index 6cf2a1b..6fa2f05 100644
--- a/ndn-cpp/key.hpp
+++ b/ndn-cpp/key.hpp
@@ -77,7 +77,7 @@
     *   If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest. 
                                 */
   Name keyName_;                /**< The key name (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
-  ndn_KeyNameType keyNameType_; /**< The type of data for keyName_ (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
+  ndn_KeyNameType keyNameType_; /**< The type of data for keyName_, -1 for none. (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
 };
   
 }