Skip to content

A simple C++ class for fast parsing XML files with a minimum overhead

Notifications You must be signed in to change notification settings

nizzebro/XmlParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XmlParser

A simple C++ class for parsing large XML, aimed at a maximum speed and minimum overhead.
Works as a stream with its own buffer reading fixed-sized chunks. Entities are processed one-by-one.
Currently supports utf-8 only.

XmlParser p;
p.openFile("D:\\sample.xml");
while(p.next())
{
    if(p.isElement("fruits"))
    {
        for(auto & a : p.getAttributes())
        { 
            std::cout << a.name << '=' << a.value << '\n';
        }
        auto i = p.getLevel();
        while(p.next(i)) // loop until </fruits> (or <fruits/> - which returns immediately)
        {
            if(p.isText("apples")) // a text block of an <apples> element ? 
            {
                std::cout << "The text of <apples> : " << '\n' << p.text << '\n'; 
                for(auto & elem : p.path)
                {
                    std::cout << elem.getName() << '\\'; // path
                }
                std::cout << '\n';
            }
        }
        std::cout << "the end-tag </fruits> is reached" << '\n';
    }
    else if(p.isPI() || p.isDTD() || p.isComment())
    {
        std::cout << p.text; // the tag's text
    }
}
p.closeFile(); 

About

A simple C++ class for fast parsing XML files with a minimum overhead

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages