C++ pugixml Installation














































C++ pugixml Installation




 
  

  pugixml  Installation :

     Step 1: Download and install TinyXML

        pugixml is distributed in source form. You can either download a source distribution or clone the Git         repository.

 1. Source distributions
 
       You can download the latest source distribution as an archive:
 
  For windows:
      pugixml-1.10.zip (Windows line endings) . Download it by using 
  URL     https://github.com/zeux/pugixml/releases/download/v1.10/pugixml-1.10.zip
 

  For Unix:
      pugixml-1.10.tar.gz (Unix line endings) . Download it by using 
  URL  https://github.com/zeux/pugixml/releases/download/v1.10/pugixml-1.10.tar.gz


    The distribution contains library source, documentation and some code examples. After downloading   the   distribution, install pugixml by extracting all files from the compressed archive.

 
 2. Git repository
       The Git repository is located at https://github.com/zeux/pugixml/. There is a Git tag "v{version}" for   each   version; also there is the "latest" tag, which always points to the latest stable release.

 For example, to checkout the current version, you can use this command:

  git clone https://github.com/zeux/pugixml
  cd pugixml
  git checkout v1.10

  The repository contains library source, documentation, code examples and full unit test suite.

  Use latest tag if you want to automatically get new versions. Use other tags if you want to switch to   new   versions only explicitly. 

     Step 2: Configure

     The complete pugixml source consists of three files - one source file, pugixml.cpp, and two header               files, pugixml.hpp and pugiconfig.hpp.

     pugixml.hpp is the primary header which you need to include in order to use pugixml classes/functions.
 pugixml.hpp is either in the current directory or in one of include directories of your projects, so that 
 #include "pugixml.hpp" can find the header

     pugiconfig.hpp is a supplementary configuration file.

  Copy the following files to your project folder
  • pugiconfig.hpp
  • pugixml.hpp
  • pugixml.cpp


     Step 3: Try one simple example

Book.xml file :
<?xml version="1.0" ?>
<catalog>
    <book id="bk101" edition="6th edition">
        <author fName="Gambardella" mName="Vijay" lName="Matthew" />
        <title>XML Developer&apos;s Guide</title>
        <genre>Computer</genre>
        <price>44.95</price>
        <publish_date>2000-10-01</publish_date>
        <description>An in-depth look at creating applications with XML.</description>
    </book>
    <book id="bk102" edition="3rd edition">
        <author fName="Ralls"  mName ="Raj" lName="Kim" />
        <title>Midnight Rain</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-12-16</publish_date>
        <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
    </book>
    <book id="bk103" edition="2nd edition">
        <author fName="Corets" mName="Shekhar" lName="Eva" />
        <title>Maeve Ascendant</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-11-17</publish_date>
        <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description>
    </book>
</catalog>


Demoxml.cpp file :

#include "pugixml.hpp"

#include <iostream>
using namespace std;

int main()
{

    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file("Book.xml");

    pugi::xml_node book1 = doc.child("catalog").child("book");      //check whethert the file is loaded successfully   

    cout << "Load result: " << result.description() <<endl<<endl;  
 
    cout<<" Books Ids :"<<endl<<endl;

    cout<<" Book 1 Id : " << book1.attribute("id").value() << endl;   //get the value of attribute id of book1



    pugi::xml_node book2 = book1.next_sibling();

    cout<<" Book 2 Id : " << book2.attribute("id").value() << endl;     //get the value of attribute id of book2

  
    
    pugi::xml_node book3 = book2.next_sibling();

    cout<<" Book 3 Id : " << book3.attribute("id").value() << endl;    //get the value of attribute id of book3

  
     

}

   Finally run the program by using following commands:

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

C:/Users/hp/Desktop/pugixmlDemo>
Demoxml.exe
Load result: No error

Books Ids :

Book 1 Id : bk101
Book 2 Id : bk102
Book 3 Id : bk103


More Articles of Nikita Kukreja:

Name Views Likes
C++ tinyxml TiXmlAttribute::Name() 127 9
C++ tinyxml TiXmlAttribute::SetName() 102 8
C++ tinyxml TiXmlElement::RemoveAttribute() 84 3
C++ tinyxml TiXmlDocument::RootElement() 112 1
C++ pugixml pugi::xml_document::load_buffer_inplace( ) 123 7
C++ pugixml pugi::xml_document::load_buffer( ) 125 5
C++ pugixml pugi::xml_node::prepend_child( ) 105 5
C++ pugixml pugi::xml_node::find_child_by_attribute( ) 137 5
C++ pugixml pugi::xml_text::get( ) 108 5
C++ pugixml pugi::xml_text::as_string( ) 118 5
C++ pugixml pugi::xml_node::select_node( ) 139 6
C++ pugixml pugi::xml_node::select_nodes( ) 98 5
C++ pugixml pugi::xml_text::as_uint( ) 102 5
C++ pugixml pugi::xml_text::as_int( ) 108 5
C++ pugixml pugi::xml_text::as_double( ) 98 5
C++ pugixml pugi::xml_text::as_bool( ) 93 6
C++ pugixml pugi::xml_node::find_attribute( ) 123 5
C++ pugixml pugi::xml_node::find_child( ) 111 5
C++ pugixml pugi::xml_node::find_node( ) 111 6
C++ pugixml pugi::xml_node::text( ) 94 5
C++ pugixml pugi::xml_node::children( ) 106 5
C++ pugixml pugi::xml_node::attributes( ) 95 4
C++ pugixml pugi::xml_node::attributes_end( ) 89 6
C++ pugixml pugi::xml_node::attributes_begin( ) 97 7
C++ pugixml pugi::xml_node::end( ) 82 7
C++ pugixml pugi::xml_node::begin( ) 108 5
C++ pugixml pugi::xml_node::attribute( ) 97 6
C++ pugixml pugi::xml_node::insert_attribute_before( ) 90 6
C++ pugixml pugi::xml_node::insert_attribute_after( ) 100 6
C++ pugixml pugi::xml_node::insert_child_before( ) 89 4
C++ pugixml pugi::xml_node::insert_child_after( ) 112 5
C++ pugixml pugi::xml_node::root( ) 108 5
C++ pugixml pugi::xml_document::document_element ( ) 101 5
C++ pugixml pugi::xml_node::parent ( ) 105 5
C++ pugixml pugi::xml_node::set_name ( ) 93 5
C++ pugixml pugi::xml_node::set_value ( ) 113 5
C++ pugixml pugi::xml_node::type ( ) 211 5
C++ pugixml pugi::xml_node::print ( ) 106 5
C++ pugixml pugi::xml_node::append_child( ) 93 5
C++ pugixml pugi::xml_node::append_attribute( ) 114 5
C++ pugixml pugi::xml_document::load_string( ) 110 6
C++ pugixml pugi::xml_node::remove_attribute( ) 96 6
C++ pugixml pugi::xml_node::remove_child( ) 97 5
C++ pugixml pugi::xml_parse_result::offset 106 5
C++ pugixml pugi::xml_parse_result::description( ) 89 5
C++ pugixml pugi::xml_node::child( ) 105 5
C++ pugixml pugi::xml_node::child_value( ) 151 5
C++ pugixml pugi::xml_node::previous_sibling( ) 85 4
C++ pugixml pugi::xml_node::next_sibling( ) 132 4
C++ pugixml pugi::xml_attribute::next_attribute( ) 84 5
C++ pugixml pugi::xml_node::last_attribute( ) 91 5
C++ pugixml pugi::xml_node::first_attribute( ) 89 5
C++ pugixml pugi::xml_node::last_child( ) 107 8
C++ pugixml pugi::xml_node::first_child( ) 110 7
C++ pugixml pugi::xml_document::save ( ) 90 5
C++ pugixml pugi::xml_node::value ( ) 84 4
C++ pugixml pugi::xml_document::save_file ( ) 99 5
C++ pugixml pugi::xml_document::load_file ( ) 93 6
C++ pugixml Installation 194 5
C++ pugixml Introduction 76 7
C++ tinyxml TiXmlAttribute::SetName() 88 5
C++ tinyxml TiXmlAttribute::Name() 73 6
C++ tinyxml TiXmlAttribute::Previous() 60 5
C++ tinyxml TiXmlAttribute::Next() 102 7
C++ tinyxml TiXmlNode::NoChildren() 75 5
C++ tinyxml TiXmlNode::Clear() 85 5
C++ tinyxml TiXmlNode::RemoveChild() 75 5
C++ tinyxml TiXmlElement::RemoveAttribute() 75 6
C++ tinyxml TiXmlElement::FirstAttribute() 90 5
C++ tinyxml TiXmlElement::LastAttribute() 60 5
C++ tinyxml TiXmlElement::Attribute() 100 5
C++ tinyxml TiXmlNode::SetAttribute() 101 5
C++ tinyxml TiXmlNode::LinkEndChild() 103 7
C++ tinyxml TiXmlNode::Clone() 66 5
C++ tinyxml TiXmlNode::Type() 68 5
C++ tinyxml TiXmlNode::SetValue() 94 5
C++ tinyxml TiXmlNode::Value() 76 6
C++ tinyxml TiXmlNode::NextSiblingElement() 91 6
C++ tinyxml TiXmlNode::PreviousSibling() 63 5
C++ tinyxml TiXmlNode::NextSibling() 71 6
C++ tinyxml TiXmlNode::Parent() 71 6
c++ tinyxml TiXmlNode::FirstChildElement() 75 5
C++ tinyxml TiXmlNode::ToComment() 77 6
C++ tinyxml TiXmlNode::ToDeclaration() 70 5
C++ tinyxml TiXmlNode::ToText() 76 5
C++ tinyxml TiXmlNode::ToElement() 72 5
C++ tinyxml TiXmlNode::ToDocument() 58 4
C++ tinyxml TiXmlNode::LastChild() 83 4
C++ tinyxml TiXmlNode::FirstChild() 66 4
C++ tinyxml TiXmlDocument::RootElement() 74 4
C++ tinyxml TiXmlDocument::SaveFile() 69 4
C++ tinyxml TiXMLDocument::LoadFile() 169 6
C++ tinyxml Installation 78 6
C++ tinyxml Introduction 100 6

Comments