Implement writeElementStartDTag, writeBlobDTagElement, etc.
diff --git a/ndn-cpp/c/encoding/BinaryXMLEncoder.c b/ndn-cpp/c/encoding/BinaryXMLEncoder.c
index c70a44a..c8a55f5 100644
--- a/ndn-cpp/c/encoding/BinaryXMLEncoder.c
+++ b/ndn-cpp/c/encoding/BinaryXMLEncoder.c
@@ -4,6 +4,7 @@
  * BSD license, See the LICENSE file for more information.
  */
 
+#include "../util/ndn_memory.h"
 #include "BinaryXML.h"
 #include "BinaryXMLEncoder.h"
 
@@ -14,6 +15,26 @@
 };
 
 /**
+ * Call ndn_DynamicUCharArray_ensureLength to ensure that there is enough room in the output, and copy
+ * array to the output.  This does not write a header.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @param array the array to copy
+ * @param arrayLength the length of the array
+ * @return 0 for success, else an error string
+ */
+static char *writeArray(struct ndn_BinaryXMLEncoder *self, unsigned char *array, unsigned int arrayLength)
+{
+  char *error;
+  if (error = ndn_DynamicUCharArray_ensureLength(&self->output, self->offset + arrayLength))
+    return error;
+  
+  ndn_memcpy(self->output.array + self->offset, array, arrayLength);
+	self->offset += arrayLength;
+  
+  return 0;
+}
+
+/**
  * Return the number of bytes to encode a header of value x.
  */
 static unsigned int getNEncodingBytes(unsigned int x) 
@@ -72,3 +93,42 @@
   
   return 0;
 }
+
+char *ndn_BinaryXMLEncoder_writeElementClose(struct ndn_BinaryXMLEncoder *self)
+{
+  char *error;
+  if (error = ndn_DynamicUCharArray_ensureLength(&self->output, self->offset + 1))
+    return error;
+  
+	self->output.array[self->offset] = ndn_BinaryXML_CLOSE;
+	self->offset += 1;
+  
+  return 0;
+}
+
+char *ndn_BinaryXMLEncoder_writeBlob(struct ndn_BinaryXMLEncoder *self, unsigned char *value, unsigned int valueLength)
+{
+  char *error;
+  if (error = ndn_BinaryXMLEncoder_encodeTypeAndValue(self, ndn_BinaryXML_BLOB, valueLength))
+    return error;
+  
+  if (error = writeArray(self, value, valueLength))
+    return error;
+  
+  return 0;
+}
+
+char *ndn_BinaryXMLEncoder_writeBlobDTagElement(struct ndn_BinaryXMLEncoder *self, unsigned int tag, unsigned char *value, unsigned int valueLength)
+{
+  char *error;
+  if (error = ndn_BinaryXMLEncoder_writeElementStartDTag(self, tag))
+    return error;
+  
+  if (error = ndn_BinaryXMLEncoder_writeBlob(self, value, valueLength))
+    return error;  
+  
+  if (error = ndn_BinaryXMLEncoder_writeElementClose(self))
+    return error;
+  
+  return 0;
+}
diff --git a/ndn-cpp/c/encoding/BinaryXMLEncoder.h b/ndn-cpp/c/encoding/BinaryXMLEncoder.h
index e606dee..8c5047c 100644
--- a/ndn-cpp/c/encoding/BinaryXMLEncoder.h
+++ b/ndn-cpp/c/encoding/BinaryXMLEncoder.h
@@ -8,11 +8,15 @@
 #define	NDN_BINARYXMLENCODER_H
 
 #include "../util/DynamicUCharArray.h"
+#include "BinaryXML.h"
 
 #ifdef	__cplusplus
 extern "C" {
 #endif
 
+/** An ndn_BinaryXMLEncoder struct is used by all the encoding functions.  You should initialize it with
+ *  ndn_BinaryXMLEncoder_init.
+ */
 struct ndn_BinaryXMLEncoder {
   struct ndn_DynamicUCharArray output; /**< receives the encoded output */
   unsigned int offset;             /**< the offset into output.array for the next encoding */
@@ -28,14 +32,59 @@
  */
 static inline void ndn_BinaryXMLEncoder_init
   (struct ndn_BinaryXMLEncoder *self, unsigned char *outputArray, unsigned int outputArrayLength, 
-   unsigned char (*reallocFunction)(unsigned char *, unsigned int)) 
+   unsigned char * (*reallocFunction)(unsigned char *, unsigned int)) 
 {
   ndn_DynamicUCharArray_init(&self->output, outputArray, outputArrayLength, reallocFunction);
   self->offset = 0;
 }
 
+/**
+ * Encode a header with the type and value and write it to self->output.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @param type the header type
+ * @param value the header value
+ * @return 0 for success, else an error string
+ */
 char *ndn_BinaryXMLEncoder_encodeTypeAndValue(struct ndn_BinaryXMLEncoder *self, unsigned int type, unsigned int value);
 
+/**
+ * Write an element start header using DTAG with the tag to self->output.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @param tag the DTAG tag
+ * @return 0 for success, else an error string
+ */
+static inline char *ndn_BinaryXMLEncoder_writeElementStartDTag(struct ndn_BinaryXMLEncoder *self, unsigned int tag) 
+{
+  return ndn_BinaryXMLEncoder_encodeTypeAndValue(self, ndn_BinaryXML_DTAG, tag);
+}
+
+/**
+ * Write an element close to self->output.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @return 0 for success, else an error string
+ */
+char *ndn_BinaryXMLEncoder_writeElementClose(struct ndn_BinaryXMLEncoder *self);
+
+/**
+ * Write a BLOB header, then the bytes of the blob value to self->output.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @param value an array of bytes for the blob value
+ * @param valueLength the length of the array
+ * @return 0 for success, else an error string
+ */
+char *ndn_BinaryXMLEncoder_writeBlob(struct ndn_BinaryXMLEncoder *self, unsigned char *value, unsigned int valueLength);
+
+/**
+ * Write an element start header using DTAG with the tag to self->output, then the blob, then an element close.
+ * (If you want to just write the blob, use ndn_BinaryXMLEncoder_writeBlob .)
+ * @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 string
+ */
+char *ndn_BinaryXMLEncoder_writeBlobDTagElement(struct ndn_BinaryXMLEncoder *self, unsigned int tag, unsigned char *value, unsigned int valueLength);
+
 #ifdef	__cplusplus
 }
 #endif