C++ pugixml pugi::xml_node::type ( )














































C++ pugixml pugi::xml_node::type ( )




  
  
pugi::xml_node::type ( ) :
type( ) of xml_node is used to get node type.

The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION. Enumerated values for the return type of type() i.e xml_node_type are:

0 - node_null
1 - node_element
2 - node_pcdata
3 - node_cdata
4 - node_comment
5 - node_pi
6 - node_declaration


Syntax :

xml_node_type pugi::xml_node::type ( ) const


         Try one simple example of using type() of pugi::xml_node :


Animal.xml file :



    <?xml version="1.0" encoding="ISO-8859-1"?>
    <animalList> <animal> <name>Herby</name> <species>Elephant</species> <dateOfBirth>23-04-1992</dateOfBirth> <veterinarianName>Dr. Hal Brown</veterinarianName> <trainerName>Bob Fisk</trainerName> </animal> <animal> <name>Sheldon</name> <species>parrot</species> <dateOfBirth>30-09-1998</dateOfBirth> <veterinarianName>Dr. Kevin Willson</veterinarianName> <trainerName>Eli Wendel</trainerName> </animal> <animal> <name>Dippy</name> <species>penguin</species> <dateOfBirth>08-06-2000</dateOfBirth> <veterinarianName>Dr. Barbara Swayne</veterinarianName> <trainerName>Waxman</trainerName> </animal>     </animalList>



        Demotype.cpp file:   


/*include necessary header files*/ #include <iostream> #include <cstdlib> #include "pugixml.hpp" using namespace std; void print() { cout<<endl; cout<<" The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION. "<<endl<<endl; cout<<" 0 - node_null "<<endl; cout<<" 1 - node_element "<<endl; cout<<" 2 - node_pcdata "<<endl; cout<<" 3 - node_cdata "<<endl; cout<<" 4 - node_comment "<<endl; cout<<" 5 - node_pi "<<endl; cout<<" 6 - node_declaration "<<endl<<endl; } int main() { print(); pugi::xml_document xmlDocument; xmlDocument.load_file("Animal.xml"); cout<<"Value : XML Document Animal.xml "<< " :: Type : "<<xmlDocument.type()<<endl; pugi::xml_node animList = xmlDocument.first_child(); //get the first child of the xml document i.e animalList cout<<"Value : "<<animList.name()<<" :: Type : "<<animList.type() <<endl; //get the type of animalList pugi::xml_node anim=animList.first_child(); //get the first child of animList i.e animal cout<<"Value : "<<anim.name()<<" :: Type : "<<anim.type() <<endl; //get the type of animal pugi::xml_node traName = anim.last_child(); //get last child of animal i.e trainerName cout<<"Value : "<<traName.name()<<" :: Type : "<<traName.type() <<endl; //get the type of trainerName pugi::xml_node trainer = traName.first_child(); //get the first child of trainerName i.e Bob Fisk (Text of trainerName) cout<<"Value : "<<trainer.value()<<" :: Type : "<<trainer.type()<<endl; //get the type of trainerName i.e Bob Fisk (Text of trainerName) return 0; }





        Finally run the program by using following commands:


C:/Users/hp/Desktop/pugixmlDemo>g++ Demotype.cpp pugixml.cpp -o Demotype.exe

C:/Users/hp/Desktop/pugixmlDemo>Demotype.exe

The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION.

0 - node_null
1 - node_element
2 - node_pcdata
3 - node_cdata
4 - node_comment
5 - node_pi
6 - node_declaration

Value : XML Document Animal.xml :: Type : 1
Value : animalList :: Type : 2
Value : animal :: Type : 2
Value : trainerName :: Type : 2
Value : Bob Fisk :: Type : 3



More Articles of Nikita Kukreja:

Name Views Likes
C++ tinyxml TiXmlAttribute::Name() 177 9
C++ tinyxml TiXmlAttribute::SetName() 138 8
C++ tinyxml TiXmlElement::RemoveAttribute() 124 3
C++ tinyxml TiXmlDocument::RootElement() 165 1
C++ pugixml pugi::xml_document::load_buffer_inplace( ) 195 7
C++ pugixml pugi::xml_document::load_buffer( ) 240 5
C++ pugixml pugi::xml_node::prepend_child( ) 166 5
C++ pugixml pugi::xml_node::find_child_by_attribute( ) 268 5
C++ pugixml pugi::xml_text::get( ) 166 5
C++ pugixml pugi::xml_text::as_string( ) 210 5
C++ pugixml pugi::xml_node::select_node( ) 243 6
C++ pugixml pugi::xml_node::select_nodes( ) 203 5
C++ pugixml pugi::xml_text::as_uint( ) 162 5
C++ pugixml pugi::xml_text::as_int( ) 164 5
C++ pugixml pugi::xml_text::as_double( ) 144 5
C++ pugixml pugi::xml_text::as_bool( ) 136 6
C++ pugixml pugi::xml_node::find_attribute( ) 294 5
C++ pugixml pugi::xml_node::find_child( ) 177 5
C++ pugixml pugi::xml_node::find_node( ) 211 6
C++ pugixml pugi::xml_node::text( ) 129 5
C++ pugixml pugi::xml_node::children( ) 161 5
C++ pugixml pugi::xml_node::attributes( ) 134 4
C++ pugixml pugi::xml_node::attributes_end( ) 129 6
C++ pugixml pugi::xml_node::attributes_begin( ) 139 7
C++ pugixml pugi::xml_node::end( ) 115 7
C++ pugixml pugi::xml_node::begin( ) 157 5
C++ pugixml pugi::xml_node::attribute( ) 141 6
C++ pugixml pugi::xml_node::insert_attribute_before( ) 136 6
C++ pugixml pugi::xml_node::insert_attribute_after( ) 155 6
C++ pugixml pugi::xml_node::insert_child_before( ) 138 4
C++ pugixml pugi::xml_node::insert_child_after( ) 162 5
C++ pugixml pugi::xml_node::root( ) 161 5
C++ pugixml pugi::xml_document::document_element ( ) 149 5
C++ pugixml pugi::xml_node::parent ( ) 147 5
C++ pugixml pugi::xml_node::set_name ( ) 148 5
C++ pugixml pugi::xml_node::set_value ( ) 176 5
C++ pugixml pugi::xml_node::type ( ) 274 5
C++ pugixml pugi::xml_node::print ( ) 172 5
C++ pugixml pugi::xml_node::append_child( ) 166 5
C++ pugixml pugi::xml_node::append_attribute( ) 190 5
C++ pugixml pugi::xml_document::load_string( ) 209 6
C++ pugixml pugi::xml_node::remove_attribute( ) 141 6
C++ pugixml pugi::xml_node::remove_child( ) 154 5
C++ pugixml pugi::xml_parse_result::offset 154 5
C++ pugixml pugi::xml_parse_result::description( ) 132 5
C++ pugixml pugi::xml_node::child( ) 159 5
C++ pugixml pugi::xml_node::child_value( ) 282 5
C++ pugixml pugi::xml_node::previous_sibling( ) 135 4
C++ pugixml pugi::xml_node::next_sibling( ) 210 4
C++ pugixml pugi::xml_attribute::next_attribute( ) 134 5
C++ pugixml pugi::xml_node::last_attribute( ) 142 5
C++ pugixml pugi::xml_node::first_attribute( ) 141 5
C++ pugixml pugi::xml_node::last_child( ) 158 8
C++ pugixml pugi::xml_node::first_child( ) 189 7
C++ pugixml pugi::xml_document::save ( ) 141 5
C++ pugixml pugi::xml_node::value ( ) 144 4
C++ pugixml pugi::xml_document::save_file ( ) 192 5
C++ pugixml pugi::xml_document::load_file ( ) 160 6
C++ pugixml Installation 414 5
C++ pugixml Introduction 173 7
C++ tinyxml TiXmlAttribute::SetName() 122 5
C++ tinyxml TiXmlAttribute::Name() 105 6
C++ tinyxml TiXmlAttribute::Previous() 91 5
C++ tinyxml TiXmlAttribute::Next() 138 7
C++ tinyxml TiXmlNode::NoChildren() 107 5
C++ tinyxml TiXmlNode::Clear() 142 5
C++ tinyxml TiXmlNode::RemoveChild() 115 5
C++ tinyxml TiXmlElement::RemoveAttribute() 118 6
C++ tinyxml TiXmlElement::FirstAttribute() 138 5
C++ tinyxml TiXmlElement::LastAttribute() 87 5
C++ tinyxml TiXmlElement::Attribute() 171 5
C++ tinyxml TiXmlNode::SetAttribute() 150 5
C++ tinyxml TiXmlNode::LinkEndChild() 152 7
C++ tinyxml TiXmlNode::Clone() 107 5
C++ tinyxml TiXmlNode::Type() 103 5
C++ tinyxml TiXmlNode::SetValue() 125 5
C++ tinyxml TiXmlNode::Value() 104 6
C++ tinyxml TiXmlNode::NextSiblingElement() 141 6
C++ tinyxml TiXmlNode::PreviousSibling() 93 5
C++ tinyxml TiXmlNode::NextSibling() 101 6
C++ tinyxml TiXmlNode::Parent() 100 6
c++ tinyxml TiXmlNode::FirstChildElement() 116 5
C++ tinyxml TiXmlNode::ToComment() 111 6
C++ tinyxml TiXmlNode::ToDeclaration() 124 5
C++ tinyxml TiXmlNode::ToText() 116 5
C++ tinyxml TiXmlNode::ToElement() 112 5
C++ tinyxml TiXmlNode::ToDocument() 90 4
C++ tinyxml TiXmlNode::LastChild() 123 4
C++ tinyxml TiXmlNode::FirstChild() 109 4
C++ tinyxml TiXmlDocument::RootElement() 112 4
C++ tinyxml TiXmlDocument::SaveFile() 97 4
C++ tinyxml TiXMLDocument::LoadFile() 250 6
C++ tinyxml Installation 108 6
C++ tinyxml Introduction 154 6

Comments