Implement name encoding.
diff --git a/ndn-cpp/c/encoding/BinaryXMLName.c b/ndn-cpp/c/encoding/BinaryXMLName.c
index 603cae3..4e3f4d7 100644
--- a/ndn-cpp/c/encoding/BinaryXMLName.c
+++ b/ndn-cpp/c/encoding/BinaryXMLName.c
@@ -4,13 +4,27 @@
  * BSD license, See the LICENSE file for more information.
  */
 
+#include "BinaryXMLEncoder.h"
 #include "BinaryXMLDecoder.h"
-#include "BinaryXML.h"
 #include "BinaryXMLName.h"
 
 char *ndn_encodeBinaryXMLName(struct ndn_Name *name, struct ndn_BinaryXMLEncoder *encoder)
 {
+  char *error;
+  if (error = ndn_BinaryXMLEncoder_writeElementStartDTag(encoder, ndn_BinaryXML_DTag_Name))
+    return error;
   
+  unsigned int i;
+  for (i = 0; i < name->nComponents; ++i) {
+    if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
+        (encoder, ndn_BinaryXML_DTag_Component, name->components[i].value, name->components[i].valueLength))
+      return error;
+	}
+  
+	if (error = ndn_BinaryXMLEncoder_writeElementClose(encoder))
+    return error;
+  
+  return 0;
 }
 
 char *ndn_decodeBinaryXMLName(struct ndn_Name *name, unsigned char *input, unsigned int inputLength)
diff --git a/ndn-cpp/c/encoding/BinaryXMLName.h b/ndn-cpp/c/encoding/BinaryXMLName.h
index ce46097..58552c5 100644
--- a/ndn-cpp/c/encoding/BinaryXMLName.h
+++ b/ndn-cpp/c/encoding/BinaryXMLName.h
@@ -8,7 +8,7 @@
 #define	NDN_BINARYXMLNAME_H
 
 #include "../Name.h"
-#include "../util/DynamicUCharArray.h"
+#include "BinaryXMLEncoder.h"
 
 #ifdef	__cplusplus
 extern "C" {
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
index b453794..9d7b79c 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
@@ -7,12 +7,28 @@
 #include <stdexcept>
 #include "../c/encoding/BinaryXMLName.h"
 #include "../Name.hpp"
+#include "BinaryXMLEncoder.hpp"
 #include "BinaryXMLWireFormat.hpp"
 
+using namespace std;
+
 namespace ndn {
 
 BinaryXMLWireFormat BinaryXMLWireFormat::instance_;
 
+void BinaryXMLWireFormat::encodeName(Name &name, vector<unsigned char> &output) 
+{
+  struct ndn_Name nameStruct;
+  struct ndn_NameComponent components[100];
+  ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
+  name.get(nameStruct);
+
+  BinaryXMLEncoder encoder;
+  ndn_encodeBinaryXMLName(&nameStruct, encoder.getEncoder());
+          
+  output = vector<unsigned char>(encoder.getEncoder()->output.array, encoder.getEncoder()->output.array + encoder.getEncoder()->offset);
+}
+
 void BinaryXMLWireFormat::decodeName(Name &name, const unsigned char *input, unsigned int inputLength)
 {
   struct ndn_NameComponent components[100];
@@ -22,10 +38,8 @@
   char *error;
   if (error = ndn_decodeBinaryXMLName(&nameStruct, (unsigned char *)input, inputLength))
     throw std::runtime_error(error);
-  
-  name.clear();
-  for (int i = 0; i < nameStruct.nComponents; ++i)
-    name.addComponent(nameStruct.components[i].value, nameStruct.components[i].valueLength);
+
+  name.set(nameStruct);
 }
 
 }
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
index 46f0d21..e6d7c8a 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
@@ -14,7 +14,7 @@
 
 class BinaryXMLWireFormat : public WireFormat {
 public:
-  //virtual void encodeName(Name &name, std::vector<unsigned char> &output);
+  virtual void encodeName(Name &name, std::vector<unsigned char> &output);
   virtual void decodeName(Name &name, const unsigned char *input, unsigned int inputLength);
 
   //virtual void encodeInterest(Interest &interest, std::vector<unsigned char> &output);
diff --git a/test/test-encode-decode-interest.cpp b/test/test-encode-decode-interest.cpp
index f7e9113..d32d966 100644
--- a/test/test-encode-decode-interest.cpp
+++ b/test/test-encode-decode-interest.cpp
@@ -39,11 +39,16 @@
 int main(int argc, char** argv)
 {
   try {
-    
     Name name;
     name.decode(Name1, sizeof(Name1));
     cout << "Name " << name.to_uri() << endl;
     
+    vector<unsigned char> encoding;
+    name.encode(encoding);
+    unsigned char *encodingBuffer = &encoding[0];
+    unsigned int encodingLength = encoding.size();
+    cout << "Name encoding length " << encodingLength << " vs. sizeof(Name1) " << sizeof(Name1) << endl;
+    
   } catch (exception &e) {
     cout << "exception " << e.what() << endl;
   }