#define MiX_ATTRIBUTE_CPP_

#include "Attribute.h"

#include <sstream>

namespace MiX{
  //dmy_itはcreateで第三引数を省略するためのトリック
  template <class charT,class char_traits,class xml_traits>
  const typename NodeList<charT,char_traits,xml_traits>::iterator 
  Attribute<charT,char_traits,xml_traits>::dmy_it=NodeList<charT,char_traits,xml_traits>::iterator();

  template <class charT,class char_traits,class xml_traits>
  XMLString<charT,char_traits,xml_traits> Attribute<charT,char_traits,xml_traits>::getFullName()const {
    string_type nsn;
    if( getParent().getType()==Node_Element ) {
      const element_type& el = dynamic_cast<const element_type&>(getParent());
      if( !getURL().empty() && getURL()!=el.getURL() ) {
	nsn = el.queryNSName( getURL() );
	nsn += xml_traits::colon();
      }
    }
    nsn += getName();
    return nsn;
  }

  template <class charT,class char_traits,class xml_traits>
  XMLString<charT,char_traits,xml_traits> Attribute<charT,char_traits,xml_traits>::toString(bool bIndent,int iIndentOffset)const{
    std::basic_stringstream<charT,char_traits> ss;
    
    ss << getFullName() << xml_traits::eq() << xml_traits::dblquote()
       << getValue() << xml_traits::dblquote();
    return ss.str();
  }
  
  template <class charT,class char_traits,class xml_traits>
  Attribute<charT,char_traits,xml_traits>& Attribute<charT,char_traits,xml_traits>::create(const string_type& key,const string_type& ns,const string_type& val,nodecontainer_type& parent){
    this_type* newattr = new this_type(key,ns,val);
    parent.getChildren().push_back(newattr);
    newattr->setParent(parent);
    return *newattr;
  }
  
}
