~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to XML/samples/DOMParser/src/DOMParser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// DOMParser.cpp
 
3
//
 
4
// $Id: //poco/1.2/XML/samples/DOMParser/src/DOMParser.cpp#1 $
 
5
//
 
6
// This sample demonstrates the DOMParser, AutoPtr and
 
7
// NodeIterator classes.
 
8
//
 
9
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
10
// and Contributors.
 
11
//
 
12
// Permission is hereby granted, free of charge, to any person or organization
 
13
// obtaining a copy of the software and accompanying documentation covered by
 
14
// this license (the "Software") to use, reproduce, display, distribute,
 
15
// execute, and transmit the Software, and to prepare derivative works of the
 
16
// Software, and to permit third-parties to whom the Software is furnished to
 
17
// do so, all subject to the following:
 
18
// 
 
19
// The copyright notices in the Software and this entire statement, including
 
20
// the above license grant, this restriction and the following disclaimer,
 
21
// must be included in all copies of the Software, in whole or in part, and
 
22
// all derivative works of the Software, unless such copies or derivative
 
23
// works are solely in the form of machine-executable object code generated by
 
24
// a source language processor.
 
25
// 
 
26
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
27
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
28
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
29
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
30
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
31
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
32
// DEALINGS IN THE SOFTWARE.
 
33
//
 
34
 
 
35
 
 
36
#include "Poco/DOM/DOMParser.h"
 
37
#include "Poco/DOM/Document.h"
 
38
#include "Poco/DOM/NodeIterator.h"
 
39
#include "Poco/DOM/NodeFilter.h"
 
40
#include "Poco/DOM/AutoPtr.h"
 
41
#include "Poco/SAX/InputSource.h"
 
42
#include "Poco/Exception.h"
 
43
#include <iostream>
 
44
 
 
45
 
 
46
using Poco::XML::DOMParser;
 
47
using Poco::XML::InputSource;
 
48
using Poco::XML::Document;
 
49
using Poco::XML::NodeIterator;
 
50
using Poco::XML::NodeFilter;
 
51
using Poco::XML::Node;
 
52
using Poco::XML::AutoPtr;
 
53
using Poco::Exception;
 
54
 
 
55
 
 
56
int main(int argc, char** argv)
 
57
{
 
58
        // Parse an XML document from standard input
 
59
        // and use a NodeIterator to print out all nodes.
 
60
        
 
61
        InputSource src(std::cin);
 
62
        try
 
63
        {
 
64
                DOMParser parser;
 
65
                AutoPtr<Document> pDoc = parser.parse(&src);
 
66
                
 
67
                NodeIterator it(pDoc, NodeFilter::SHOW_ALL);
 
68
                Node* pNode = it.nextNode();
 
69
                while (pNode)
 
70
                {
 
71
                        std::cout << pNode->nodeName() << ":" << pNode->nodeValue() << std::endl;
 
72
                        pNode = it.nextNode();
 
73
                }
 
74
        }
 
75
        catch (Exception& exc)
 
76
        {
 
77
                std::cerr << exc.displayText() << std::endl;
 
78
        }
 
79
        
 
80
        return 0;
 
81
}