| 1 | // |
|---|---|
| 2 | // DOMParser.cpp |
| 3 | // |
| 4 | // This sample demonstrates the DOMParser, AutoPtr and |
| 5 | // NodeIterator classes. |
| 6 | // |
| 7 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 8 | // and Contributors. |
| 9 | // |
| 10 | // SPDX-License-Identifier: BSL-1.0 |
| 11 | // |
| 12 | |
| 13 | |
| 14 | #include "Poco/DOM/DOMParser.h" |
| 15 | #include "Poco/DOM/Document.h" |
| 16 | #include "Poco/DOM/NodeIterator.h" |
| 17 | #include "Poco/DOM/NodeFilter.h" |
| 18 | #include "Poco/DOM/AutoPtr.h" |
| 19 | #include "Poco/SAX/InputSource.h" |
| 20 | #include "Poco/Exception.h" |
| 21 | #include <iostream> |
| 22 | |
| 23 | |
| 24 | using Poco::XML::DOMParser; |
| 25 | using Poco::XML::InputSource; |
| 26 | using Poco::XML::Document; |
| 27 | using Poco::XML::NodeIterator; |
| 28 | using Poco::XML::NodeFilter; |
| 29 | using Poco::XML::Node; |
| 30 | using Poco::XML::AutoPtr; |
| 31 | using Poco::Exception; |
| 32 | |
| 33 | |
| 34 | int main(int argc, char** argv) |
| 35 | { |
| 36 | // Parse an XML document from standard input |
| 37 | // and use a NodeIterator to print out all nodes. |
| 38 | |
| 39 | InputSource src(std::cin); |
| 40 | try |
| 41 | { |
| 42 | DOMParser parser; |
| 43 | AutoPtr<Document> pDoc = parser.parse(&src); |
| 44 | |
| 45 | NodeIterator it(pDoc, NodeFilter::SHOW_ALL); |
| 46 | Node* pNode = it.nextNode(); |
| 47 | while (pNode) |
| 48 | { |
| 49 | std::cout << pNode->nodeName() << ":"<< pNode->nodeValue() << std::endl; |
| 50 | pNode = it.nextNode(); |
| 51 | } |
| 52 | } |
| 53 | catch (Exception& exc) |
| 54 | { |
| 55 | std::cerr << exc.displayText() << std::endl; |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 |