Added writeOptionalBlobDTagElement
diff --git a/ndn-cpp/c/encoding/BinaryXMLEncoder.h b/ndn-cpp/c/encoding/BinaryXMLEncoder.h
index c2df389..ee5d773 100644
--- a/ndn-cpp/c/encoding/BinaryXMLEncoder.h
+++ b/ndn-cpp/c/encoding/BinaryXMLEncoder.h
@@ -86,6 +86,23 @@
 ndn_Error ndn_BinaryXMLEncoder_writeBlobDTagElement(struct ndn_BinaryXMLEncoder *self, unsigned int tag, unsigned char *value, unsigned int valueLength);
 
 /**
+ * If value or valueLen is 0, then do nothing, otherwise call ndn_BinaryXMLEncoder_writeBlobDTagElement.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @param tag the DTAG tag
+ * @param value an array of bytes for the blob value
+ * @param valueLength the length of the array
+ * @return 0 for success, else an error code
+ */
+static inline ndn_Error ndn_BinaryXMLEncoder_writeOptionalBlobDTagElement
+  (struct ndn_BinaryXMLEncoder *self, unsigned int tag, unsigned char *value, unsigned int valueLength)
+{
+  if (value && valueLength > 0)
+    return ndn_BinaryXMLEncoder_writeBlobDTagElement(self, tag, value, valueLength);
+  else
+    return 0;
+}
+
+/**
  * Write a UDATA header, then the value as an unsigned decimal integer.
  * @param self pointer to the ndn_BinaryXMLEncoder struct
  * @param value the unsigned int
diff --git a/ndn-cpp/c/encoding/BinaryXMLInterest.c b/ndn-cpp/c/encoding/BinaryXMLInterest.c
index 6b02176..9b06a76 100644
--- a/ndn-cpp/c/encoding/BinaryXMLInterest.c
+++ b/ndn-cpp/c/encoding/BinaryXMLInterest.c
@@ -175,11 +175,9 @@
       return error;
   }
   
-  if (interest->nonce && interest->nonceLength > 0) {
-    if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
-        (encoder, ndn_BinaryXML_DTag_Nonce, interest->nonce, interest->nonceLength))
-      return error;
-  }
+  if (error = ndn_BinaryXMLEncoder_writeOptionalBlobDTagElement
+      (encoder, ndn_BinaryXML_DTag_Nonce, interest->nonce, interest->nonceLength))
+    return error;
   
 	if (error = ndn_BinaryXMLEncoder_writeElementClose(encoder))
     return error;