4
// $Id: //poco/1.2/XML/samples/DOMParser/src/DOMParser.cpp#1 $
6
// This sample demonstrates the DOMParser, AutoPtr and
7
// NodeIterator classes.
9
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
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:
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.
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.
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"
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;
56
int main(int argc, char** argv)
58
// Parse an XML document from standard input
59
// and use a NodeIterator to print out all nodes.
61
InputSource src(std::cin);
65
AutoPtr<Document> pDoc = parser.parse(&src);
67
NodeIterator it(pDoc, NodeFilter::SHOW_ALL);
68
Node* pNode = it.nextNode();
71
std::cout << pNode->nodeName() << ":" << pNode->nodeValue() << std::endl;
72
pNode = it.nextNode();
75
catch (Exception& exc)
77
std::cerr << exc.displayText() << std::endl;