diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index b801055ad88..d651f21ac55 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -258,6 +258,24 @@ in those WKT types, namely: - `CGAL::Point_3` - `CGAL::Polygon_with_holes_2` - random access range of the above types. + +\section IOstreamXML Reading Adhoc XML + +In case you have to read data in a simple xml file with a simple structure, without existing I/O libraries +the `boost::property_tree` comes in handy. +The following small example shows how to parse a file +looking like this: + + + + + + + + + + +\cgalExample{Stream_support/read_xml.cpp} */ } /* namespace CGAL */ diff --git a/Stream_support/doc/Stream_support/examples.txt b/Stream_support/doc/Stream_support/examples.txt index 25891e95051..b8fd39550b6 100644 --- a/Stream_support/doc/Stream_support/examples.txt +++ b/Stream_support/doc/Stream_support/examples.txt @@ -2,4 +2,5 @@ \example Stream_support/Linestring_WKT.cpp \example Stream_support/Point_WKT.cpp \example Stream_support/Polygon_WKT.cpp +\example Stream_support/read_xml.cpp */ diff --git a/Stream_support/examples/Stream_support/CMakeLists.txt b/Stream_support/examples/Stream_support/CMakeLists.txt index 0b27d681d69..69d953e830e 100644 --- a/Stream_support/examples/Stream_support/CMakeLists.txt +++ b/Stream_support/examples/Stream_support/CMakeLists.txt @@ -25,6 +25,8 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "Polygon_WKT.cpp" ) create_single_source_cgal_program( "Linestring_WKT.cpp" ) create_single_source_cgal_program( "read_WKT.cpp" ) + + create_single_source_cgal_program( "read_xml.cpp" ) else () message(STATUS "This project requires the CGAL library, and will not be compiled.") diff --git a/Stream_support/examples/Stream_support/data/cloud.pol b/Stream_support/examples/Stream_support/data/cloud.pol new file mode 100644 index 00000000000..c3861de634b --- /dev/null +++ b/Stream_support/examples/Stream_support/data/cloud.pol @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Stream_support/examples/Stream_support/read_xml.cpp b/Stream_support/examples/Stream_support/read_xml.cpp new file mode 100644 index 00000000000..fdbbf4b0ec3 --- /dev/null +++ b/Stream_support/examples/Stream_support/read_xml.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Point_3 Point_3; + +int main(int argc, char* argv[]){ + std::ifstream in( (argc>1)? argv[1] : "data/cloud.pol"); + boost::property_tree::ptree tree; + boost::property_tree::read_xml(in, tree); + + std::vector points; + + for(boost::property_tree::ptree::value_type& node : tree.get_child("PolySet.Polygon")){ + boost::property_tree::ptree subtree = node.second; + if( node.first == "Point" ){ + for( boost::property_tree::ptree::value_type const& v : subtree.get_child( "" ) ) { + std::string label = v.first; + + if ( label == "" ) { + Point_3 p(subtree.get( label+".X"), + subtree.get( label+".Y"), + subtree.get( label+".Z")); + points.push_back(p); + } + } + } + } + + std::cout << points.size() << " points read"<< std::endl; + return 0; +}