With this example, we see how to put and extract data from the attribute object. We also learn how to deal with namespace.
#include <iostream>
#include <ximol/ximol.hpp>
using namespace std;
using namespace ximol;
int main()
{
double d1=3.01,d2=4.1;
xml::attributes att;
set_namespace(att,"http://default_namespace.com/");
set_namespace(att,"ns1","http://namespace_1.com/");
set_namespace(att,"ns2","http://namespace_2.com/");
cout << "default namespace=" << str<std::string>::cast(get_namespace(att)) << endl;
cout << "namespace 1 =" << str<std::string>::cast(get_namespace(att,"ns1")) << endl;
cout << "namespace 2 =" << str<std::string>::cast(get_namespace(att,"ns2")) << endl;
cout << "namespace 3 =" << str<std::string>::cast(get_namespace(att,"ns3")) << endl;
cout << "default namespace=" << str<std::string>::cast(get_namespace(att,"")) << endl;
cout << "http://namespace_1.com/=" << str<std::string>::cast(get_short_namespace(att,"http://namespace_1.com/")) << endl;
cout << "http://namespace_2.com/=" << str<std::string>::cast(get_short_namespace(att,"http://namespace_2.com/")) << endl;
cout << "http://namespace_3.com/=" << str<std::string>::cast(get_short_namespace(att,"http://namespace_3.com/")) << endl;
insert_attribute(att,"the_first_one","the first one value");
insert_attribute(att,"the_first_one","the first one value replaced");
set_attribute(att,"the_first_one","the first one value replaced by a set_attributes");
set_attribute(att,"a_double",d1);
cout << "the_first_one=" << str<std::string>::cast(get_raw_attribute(att,"the_first_one")) << endl;
get_attribute(att,"a_double",d2);
cout << "d2=" << d2 << endl;
d2=1+extract_attribute<double>::get(att,"a_double");
cout << "d2=" << d2 << endl;
insert_attribute(att,"test_ns_1","the test_ns_1 value");
set_attribute(att,"test_ns_2","the test_ns_2 value");
set_attribute(att,"ns1","test_ns_3","the test_ns_3 value");
set_attribute(att,"http://namespace_1.com/","test_ns_4","the test_ns_5 value");
set_attribute(att,"conflict_name","the value with default namespace");
set_attribute(att,"ns1","conflict_name","the value with namespace 1");
set_attribute(att,"ns2","conflict_name","the value with namespace 2");
cout << "test_ns_1=" << extract_attribute<string>::get(att,"test_ns_1") << endl;;
cout << "test_ns_2=" << extract_attribute<string>::get(att,"","test_ns_2") << endl;;
cout << "test_ns_3=" << extract_attribute<string>::get(att,"ns1","test_ns_3") << endl;;
cout << "test_ns_4=" << extract_attribute<string>::get(att,"http://namespace_1.com/","test_ns_4") << endl;
cout << "test_ns_4=" << extract_attribute<string>::get(att,"test_ns_4") << endl;;
cout << "ns1:conflict_name=" << extract_attribute<string>::get(att,"http://namespace_1.com/","conflict_name") << endl;
cout << "ns2:conflict_name=" << extract_attribute<string>::get(att,"ns2","conflict_name") << endl;
cout << "conflict_name=" << extract_attribute<string>::get(att,"conflict_name") << endl;
cout << "attributes=" << att << endl;
return 0;
};