PCL
XML.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/XML.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_XML_h
53 #define __PCL_XML_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Exception.h>
60 #include <pcl/ReferenceArray.h>
61 #include <pcl/String.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
72 // ----------------------------------------------------------------------------
73 
74 class PCL_CLASS XMLDocument;
75 class PCL_CLASS XMLElement;
76 
77 // ----------------------------------------------------------------------------
78 
84 class PCL_CLASS XML
85 {
86 public:
87 
92  XML() = delete;
93 
98  XML( const XML& ) = delete;
99 
104  XML& operator =( const XML& ) = delete;
105 
110  ~XML() = delete;
111 
116  template <typename T>
117  static bool IsWhiteSpaceChar( T c )
118  {
119  return c == 0x20 || c == 9;
120  }
121 
126  template <typename T>
127  static bool IsLineBreakChar( T c )
128  {
129  return c == 0x0A || c == 0x0D;
130  }
131 
137  template <typename T>
138  static bool IsSpaceChar( T c )
139  {
140  return IsWhiteSpaceChar( c ) || IsLineBreakChar( c );
141  }
142 
148  template <typename T>
149  static bool IsNameStartChar( T c )
150  {
151  return c >= T( 'a' ) && c <= T( 'z' )
152  || c >= T( 'A' ) && c <= T( 'Z' )
153  || c == T( '_' )
154  || c == T( ':' )
155  || c >= 0xC0 && c <= 0xD6
156  || c >= 0xD8 && c <= 0xF6
157  || c >= 0xF8 && c <= 0x2FF
158  || c >= 0x370 && c <= 0x37D
159  || c >= 0x37F && c <= 0x1FFF
160  || c >= 0x200C && c <= 0x200D
161  || c >= 0x2070 && c <= 0x218F
162  || c >= 0x2C00 && c <= 0x2FEF
163  || c >= 0x3001 && c <= 0xD7FF
164  || c >= 0xF900 && c <= 0xFDCF
165  || c >= 0xFDF0 && c <= 0xFFFD
166  || uint32( c ) >= 0x10000 && uint32( c ) <= 0xEFFFF;
167  }
168 
174  template <typename T>
175  static bool IsNameChar( T c )
176  {
177  return IsNameStartChar( c )
178  || c >= T( '0' ) && c <= T( '9' )
179  || c == T( '-' )
180  || c == T( '.' )
181  || c == 0xB7
182  || c >= 0x0300 && c <= 0x036F
183  || c >= 0x203F && c <= 0x2040;
184  }
185 
191  template <typename T>
192  static bool IsRestrictedChar( T c )
193  {
194  return c >= 0x00 && c <= 0x08
195  || c >= 0x0B && c <= 0x0C
196  || c >= 0x0E && c <= 0x1F
197  || c >= 0x7F && c <= 0x84
198  || c >= 0x86 && c <= 0x9F;
199  }
200 
207  static bool IsValidName( const String& name )
208  {
209  if ( !name.IsEmpty() )
210  if ( IsNameStartChar( *name ) )
211  for ( String::const_iterator i = name.Begin(); ; )
212  {
213  if ( ++i == name.End() )
214  return true;
215  if ( !IsNameChar( *i ) )
216  break;
217  }
218  return false;
219  }
220 
226 
231  static String TrimmedSpaces( const String& text );
232 
239 
244  static String CollapsedSpaces( const String& text );
245 
262 
270  static String DecodedText( const String& text );
271 
279  {
280  return EncodedText( String( i, j ), apos );
281  }
282 
289  static String EncodedText( const String& text, bool apos = true );
290 
308 
316  static String ReferenceValue( const String& reference )
317  {
318  return ReferenceValue( reference.Begin(), reference.End() );
319  }
320 };
321 
322 // ----------------------------------------------------------------------------
323 
334 class PCL_CLASS XMLComponent
335 {
336 public:
337 
342  XMLComponent() = default;
343 
347  XMLComponent( const XMLComponent& ) = default;
348 
352  virtual ~XMLComponent()
353  {
354  }
355 
361  {
362  return m_parent;
363  }
364 
369  bool IsTopLevel() const
370  {
371  return m_parent == nullptr;
372  }
373 
374 private:
375 
376  XMLElement* m_parent = nullptr;
377 
378  friend class XMLElement;
379 };
380 
381 // ----------------------------------------------------------------------------
382 
401 namespace XMLNodeType
402 {
403  enum mask_type
404  {
405  Undefined = 0x00000000,
406  ChildNode = 0x80000000,
407  Unknown = 0x10000000,
408  Element = 0x00000001,
409  Text = 0x00000002,
410  CDATA = 0x00000004,
411  ProcessingInstructions = 0x00000008,
412  Comment = 0x00000010
413  };
414 
419  String AsString( mask_type type );
420 }
421 
428 
429 // ----------------------------------------------------------------------------
430 
437 {
442  int64 line = 0;
443 
456 
461  XMLNodeLocation() = default;
462 
467  XMLNodeLocation( int line_, int column_ )
468  : line( line_ )
469  , column( column_ )
470  {
471  }
472 
476  XMLNodeLocation( const XMLNodeLocation& ) = default;
477 
490  String ToString() const;
491 };
492 
493 // ----------------------------------------------------------------------------
494 
506 class PCL_CLASS XMLNode : public XMLComponent
507 {
508 public:
509 
514  using node_type = XMLNodeType::mask_type;
515 
521  XMLNode( node_type type )
522  : m_type( type )
523  {
524  }
525 
533  XMLNode( const XMLNode& x )
534  : m_type( x.NodeType() )
535  , m_location( x.m_location )
536  {
537  }
538 
542  ~XMLNode() override
543  {
544  }
545 
549  bool IsChildNode() const
550  {
551  return m_type.IsFlagSet( XMLNodeType::ChildNode );
552  }
553 
557  node_type NodeType() const
558  {
559  return static_cast<node_type>( XMLNodeTypes::flag_type( m_type & unsigned( ~XMLNodeType::ChildNode ) ) );
560  }
561 
566  bool IsElement() const
567  {
568  return NodeType() == XMLNodeType::Element;
569  }
570 
575  bool IsText() const
576  {
577  return NodeType() == XMLNodeType::Text;
578  }
579 
584  bool IsComment() const
585  {
586  return NodeType() == XMLNodeType::Comment;
587  }
588 
592  const XMLNodeLocation& Location() const
593  {
594  return m_location;
595  }
596 
622  virtual void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const = 0;
623 
636  virtual void SerializeAsHTML( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const
637  {
638  Serialize( text, autoFormat, indentChar, indentSize, level );
639  }
640 
645  virtual bool NLAfter( const XMLNode& previous ) const;
646 
647 private:
648 
649  XMLNodeTypes m_type;
650  XMLNodeLocation m_location;
651 
652  friend class XMLDocument;
653  friend class XMLElement;
654 };
655 
667 
668 // ----------------------------------------------------------------------------
669 
682 class PCL_CLASS XMLParseError : public Error
683 {
684 public:
685 
702  XMLParseError( const XMLNode& node, const String& whileDoing, const String& whatHappened )
703  : Error( whileDoing + node.Location().ToString() + ": " + whatHappened )
704  {
705  }
706 
723  XMLParseError( const XMLNodeLocation& where, const String& whileDoing, const String& whatHappened )
724  : Error( whileDoing + where.ToString() + ": " + whatHappened )
725  {
726  }
727 
731  XMLParseError( const XMLParseError& ) = default;
732 };
733 
734 // ----------------------------------------------------------------------------
735 
747 class PCL_CLASS XMLAttribute : public XMLComponent
748 {
749 public:
750 
755  XMLAttribute() = default;
756 
770  XMLAttribute( const String& name, const String& value = String() )
771  : m_name( name )
772  , m_value( value )
773  {
774  }
775 
779  XMLAttribute( const XMLAttribute& ) = default;
780 
784  const String& Name() const
785  {
786  return m_name;
787  }
788 
792  const String& Value() const
793  {
794  return m_value;
795  }
796 
800  void SetValue( const String& text )
801  {
802  m_value = text;
803  }
804 
811  {
812  return XML::EncodedText( m_value, false/*apos*/ );
813  }
814 
822  bool operator ==( const XMLAttribute& x ) const
823  {
824  return m_name == x.m_name;
825  }
826 
834  bool operator <( const XMLAttribute& x ) const
835  {
836  return m_name < x.m_name;
837  }
838 
839 private:
840 
841  String m_name;
842  String m_value;
843 };
844 
845 // ----------------------------------------------------------------------------
846 
861 class PCL_CLASS XMLAttributeList
862 {
863 public:
864 
870 
875 
880 
892  XMLAttributeList( const String& text )
893  {
894  Parse( text );
895  }
896 
900  XMLAttributeList() = default;
901 
905  XMLAttributeList( const XMLAttributeList& ) = default;
906 
910  int Length() const
911  {
912  return int( m_list.Length() );
913  }
914 
918  bool IsEmpty() const
919  {
920  return m_list.IsEmpty();
921  }
922 
928  const XMLAttribute& operator []( int i ) const
929  {
930  return m_list[i];
931  }
932 
938  {
939  return m_list.Begin();
940  }
941 
947  {
948  return m_list.End();
949  }
950 
951 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
956  {
957  return Begin();
958  }
959 
964  {
965  return End();
966  }
967 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
968 
973  bool HasAttribute( const String& name ) const
974  {
975  return m_list.Contains( name );
976  }
977 
983  String AttributeValue( const String& name ) const
984  {
985  const_iterator a = m_list.Search( name );
986  return (a != m_list.End()) ? a->Value() : String();
987  }
988 
1004  void SetAttribute( const String& name, const String& value )
1005  {
1006  if ( !name.IsEmpty() )
1007  {
1008  iterator a = m_list.Search( name );
1009  if ( a == m_list.End() )
1010  m_list.Add( XMLAttribute( name, value ) );
1011  else
1012  a->SetValue( value );
1013  }
1014  }
1015 
1021  void SetAttribute( const XMLAttribute& attribute )
1022  {
1023  if ( !attribute.Name().IsEmpty() )
1024  {
1025  iterator a = m_list.Search( attribute );
1026  if ( a == m_list.End() )
1027  m_list.Add( attribute );
1028  else
1029  *a = attribute;
1030  }
1031  }
1032 
1039  {
1040  SetAttribute( attribute );
1041  return *this;
1042  }
1043 
1059  void SetAttributes( const XMLAttributeList& list )
1060  {
1061  for ( auto a : list )
1062  SetAttribute( a );
1063  }
1064 
1071  {
1072  SetAttributes( list );
1073  return *this;
1074  }
1075 
1081  void RemoveAttribute( const String& name )
1082  {
1083  iterator a = m_list.Search( name );
1084  if ( a != m_list.End() )
1085  m_list.Remove( a );
1086  }
1087 
1092  void Clear()
1093  {
1094  m_list.Clear();
1095  }
1096 
1101  void Sort()
1102  {
1103  m_list.Sort();
1104  }
1105 
1127  void Parse( const String& text );
1128 
1139  void Serialize( IsoString& text ) const;
1140 
1141 private:
1142 
1143  list_implementation m_list;
1144 };
1145 
1146 // ----------------------------------------------------------------------------
1147 
1161 class PCL_CLASS XMLElement : public XMLNode
1162 {
1163 public:
1164 
1168  using iterator = XMLNodeList::iterator;
1169 
1173  using const_iterator = XMLNodeList::const_iterator;
1174 
1180 
1185  : XMLNode( XMLNodeType::Element )
1186  {
1187  }
1188 
1193  XMLElement( const String& name, const XMLAttributeList& attributes = XMLAttributeList() )
1194  : XMLNode( XMLNodeType::Element )
1195  , m_name( name )
1196  , m_attributes( attributes )
1197  {
1198  }
1199 
1205  XMLElement( XMLElement& parent, const String& name, const XMLAttributeList& attributes = XMLAttributeList() )
1206  : XMLNode( XMLNodeType::Element )
1207  , m_name( name )
1208  , m_attributes( attributes )
1209  {
1210  parent.AddChildNode( this );
1211  }
1212 
1217  XMLElement( const XMLElement& ) = delete;
1218 
1223  XMLElement& operator =( const XMLElement& ) = delete;
1224 
1229  ~XMLElement() override
1230  {
1231  DestroyChildNodes();
1232  }
1233 
1244  bool IsRootElement() const
1245  {
1246  return ParentElement() == nullptr;
1247  }
1248 
1252  const String& Name() const
1253  {
1254  return m_name;
1255  }
1256 
1261  {
1262  return m_attributes;
1263  }
1264 
1268  bool HasAttributes() const
1269  {
1270  return !m_attributes.IsEmpty();
1271  }
1272 
1277  bool HasAttribute( const String& name ) const
1278  {
1279  return m_attributes.HasAttribute( name );
1280  }
1281 
1287  String AttributeValue( const String& name ) const
1288  {
1289  return m_attributes.AttributeValue( name );
1290  }
1291 
1307  void SetAttribute( const String& name, const String& value )
1308  {
1309  XMLAttribute a( name, value );
1310  a.m_parent = this;
1311  m_attributes.SetAttribute( a );
1312  }
1313 
1319  void SetAttribute( const XMLAttribute& attribute )
1320  {
1321  XMLAttribute a( attribute );
1322  a.m_parent = this;
1323  m_attributes.SetAttribute( a );
1324  }
1325 
1331  XMLElement& operator <<( const XMLAttribute& attribute )
1332  {
1333  SetAttribute( attribute );
1334  return *this;
1335  }
1336 
1352  void SetAttributes( const XMLAttributeList& list )
1353  {
1354  for ( auto a : list )
1355  SetAttribute( a );
1356  }
1357 
1364  {
1365  SetAttributes( list );
1366  return *this;
1367  }
1368 
1374  void RemoveAttribute( const String& name )
1375  {
1376  m_attributes.RemoveAttribute( name );
1377  }
1378 
1383  {
1384  m_attributes.Clear();
1385  }
1386 
1392  {
1393  m_attributes.Sort();
1394  }
1395 
1402  template <class BP>
1403  void SortAttributes( BP p )
1404  {
1405  m_attributes.Sort( p );
1406  }
1407 
1419  void ParseAttributes( const String& text )
1420  {
1421  XMLAttributeList list( text );
1422  ClearAttributes();
1423  SetAttributes( list );
1424  }
1425 
1436  void SerializeAttributes( IsoString& text ) const
1437  {
1438  m_attributes.Serialize( text );
1439  }
1440 
1444  int ChildCount() const
1445  {
1446  return int( m_childNodes.Length() );
1447  }
1448 
1453  bool IsEmpty() const
1454  {
1455  return m_childNodes.IsEmpty();
1456  }
1457 
1463  const XMLNode& operator []( int i ) const
1464  {
1465  return m_childNodes[i];
1466  }
1467 
1473  const XMLNode& First() const
1474  {
1475  return m_childNodes.First();
1476  }
1477 
1483  const XMLNode& Last() const
1484  {
1485  return m_childNodes.Last();
1486  }
1487 
1493  {
1494  return m_childNodes.Begin();
1495  }
1496 
1502  {
1503  return m_childNodes.End();
1504  }
1505 
1506 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1511  {
1512  return Begin();
1513  }
1514 
1519  {
1520  return End();
1521  }
1522 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1523 
1524 #ifndef __PCL_NO_MUTABLE_XML_ELEMENT_ITERATORS
1525 
1531  {
1532  return m_childNodes.Begin();
1533  }
1534 
1540  {
1541  return m_childNodes.End();
1542  }
1543 
1549  {
1550  return m_childNodes.ConstBegin();
1551  }
1552 
1558  {
1559  return m_childNodes.ConstEnd();
1560  }
1561 
1562 # ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1567  {
1568  return Begin();
1569  }
1570 
1575  {
1576  return End();
1577  }
1578 # endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1579 
1580 #endif // !__PCL_NO_MUTABLE_XML_ELEMENT_ITERATORS
1581 
1585  bool HasElements() const
1586  {
1587  return m_childTypes.IsFlagSet( XMLNodeType::Element );
1588  }
1589 
1593  bool HasText() const
1594  {
1595  return m_childTypes.IsFlagSet( XMLNodeType::Text );
1596  }
1597 
1601  bool HasCDATA() const
1602  {
1603  return m_childTypes.IsFlagSet( XMLNodeType::CDATA );
1604  }
1605 
1611  {
1612  return m_childTypes.IsFlagSet( XMLNodeType::ProcessingInstructions );
1613  }
1614 
1619  bool HasComments() const
1620  {
1621  return m_childTypes.IsFlagSet( XMLNodeType::Comment );
1622  }
1623 
1631  String Text() const;
1632 
1636  void GetChildElements( child_element_list& list, bool recursive ) const
1637  {
1638  for ( const XMLNode& node : m_childNodes )
1639  if ( node.IsElement() )
1640  {
1641  const XMLElement& element = static_cast<const XMLElement&>( node );
1642  list << &element;
1643  if ( recursive )
1644  element.GetChildElements( list, recursive );
1645  }
1646  }
1647 
1655  child_element_list ChildElements( bool recursive = false ) const
1656  {
1657  child_element_list list;
1658  GetChildElements( list, recursive );
1659  return list;
1660  }
1661 
1665  void GetChildElementsByName( child_element_list& list, const String& name, bool recursive ) const
1666  {
1667  for ( const XMLNode& node : m_childNodes )
1668  if ( node.IsElement() )
1669  {
1670  const XMLElement& element = static_cast<const XMLElement&>( node );
1671  if ( element.Name() == name )
1672  {
1673  list << &element;
1674  if ( recursive )
1675  element.GetChildElementsByName( list, name, recursive );
1676  }
1677  }
1678  }
1679 
1688  child_element_list ChildElementsByName( const String& name, bool recursive = false ) const
1689  {
1690  child_element_list list;
1691  GetChildElementsByName( list, name, recursive );
1692  return list;
1693  }
1694 
1703  bool HasChildElementWithName( const String& name, bool recursive = false ) const
1704  {
1705  for ( const XMLNode& node : m_childNodes )
1706  if ( node.IsElement() )
1707  {
1708  const XMLElement& element = static_cast<const XMLElement&>( node );
1709  if ( element.Name() == name )
1710  return true;
1711  if ( recursive )
1712  if ( element.HasChildElementWithName( name, recursive ) )
1713  return true;
1714  }
1715  return false;
1716  }
1717 
1721  void GetChildNodesByType( XMLNodeList& list, XMLNodeTypes types, bool recursive ) const
1722  {
1723  for ( const XMLNode& node : m_childNodes )
1724  if ( types.IsFlagSet( node.NodeType() ) )
1725  {
1726  list << &node;
1727  if ( recursive )
1728  if ( node.IsElement() )
1729  static_cast<const XMLElement&>( node ).GetChildNodesByType( list, types, recursive );
1730  }
1731  }
1732 
1742  XMLNodeList ChildNodesByType( XMLNodeTypes types, bool recursive = false ) const
1743  {
1744  XMLNodeList list;
1745  GetChildNodesByType( list, types, recursive );
1746  return list;
1747  }
1748 
1752  template <class UP>
1753  void GetChildNodesThat( XMLNodeList& list, UP u, bool recursive ) const
1754  {
1755  for ( const XMLNode& node : m_childNodes )
1756  if ( u( node ) )
1757  {
1758  list << &node;
1759  if ( recursive )
1760  if ( node.IsElement() )
1761  static_cast<const XMLElement&>( node ).GetChildNodesThat( list, u, recursive );
1762  }
1763  }
1764 
1776  template <class UP>
1777  XMLNodeList ChildNodesThat( UP u, bool recursive = false ) const
1778  {
1779  XMLNodeList list;
1780  GetChildNodesThat( list, u, recursive );
1781  return list;
1782  }
1783 
1792  template <class UP>
1793  bool HasChildNodeThat( UP u, bool recursive = false ) const
1794  {
1795  for ( const XMLNode& node : m_childNodes )
1796  {
1797  if ( u( node ) )
1798  return true;
1799  if ( recursive )
1800  if ( node.IsElement() )
1801  if ( static_cast<const XMLElement&>( node ).HasChildNodeThat( u, recursive ) )
1802  return true;
1803  }
1804  return false;
1805  }
1806 
1813  void AddChildNode( XMLNode* node )
1814  {
1815  m_childNodes << node;
1816  node->m_parent = this;
1817  node->m_type.SetFlag( XMLNodeType::ChildNode );
1818  m_childTypes.SetFlag( node->NodeType() );
1819  }
1820 
1828  {
1829  AddChildNode( node );
1830  return *this;
1831  }
1832 
1841  {
1842  for ( XMLNode& node : nodes )
1843  AddChildNode( &node );
1844  }
1845 
1853  {
1854  AddChildNodes( nodes );
1855  return *this;
1856  }
1857 
1865  void AddChildNode( XMLNode* node, const XMLNodeLocation& location )
1866  {
1867  node->m_location = location;
1868  AddChildNode( node );
1869  }
1870 
1876  {
1877  m_childNodes.Destroy();
1878  m_childTypes = XMLNodeType::Undefined;
1879  }
1880 
1891  {
1892  XMLNodeList nodes = m_childNodes;
1893  m_childNodes.Clear();
1894  m_childTypes = XMLNodeType::Undefined;
1895  return nodes;
1896  }
1897 
1905  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
1906 
1915  void SerializeAsHTML( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
1916 
1917 private:
1918 
1919  String m_name;
1920  XMLAttributeList m_attributes;
1921  XMLNodeList m_childNodes;
1922  XMLNodeTypes m_childTypes = XMLNodeType::Undefined;
1923 };
1924 
1925 // ----------------------------------------------------------------------------
1926 
1938 
1939 // ----------------------------------------------------------------------------
1940 
1951 class PCL_CLASS XMLText : public XMLNode
1952 {
1953 public:
1954 
1980  XMLText( const String& text, bool preserveSpaces = true, bool verbatim = false )
1981  : XMLNode( XMLNodeType::Text )
1982  , m_text( preserveSpaces ? text : XML::CollapsedSpaces( XML::TrimmedSpaces( text ) ) )
1983  , m_preserveSpaces( preserveSpaces )
1984  , m_verbatim( verbatim )
1985  {
1986  }
1987 
1991  XMLText( const XMLText& ) = default;
1992 
1997  const String& Text() const
1998  {
1999  return m_text;
2000  }
2001 
2006  bool IsPreserveSpaces() const
2007  {
2008  return m_preserveSpaces;
2009  }
2010 
2017  {
2018  return XML::EncodedText( m_text );
2019  }
2020 
2029  String SpaceTransformedText( bool collapse, bool trim ) const
2030  {
2031  String text = m_text;
2032  if ( trim )
2033  text = XML::TrimmedSpaces( text );
2034  if ( collapse )
2035  text = XML::CollapsedSpaces( text );
2036  return text;
2037  }
2038 
2046  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2047 
2057  bool NLAfter( const XMLNode& previous ) const override
2058  {
2059  return !m_preserveSpaces;
2060  }
2061 
2062 private:
2063 
2064  String m_text; // N.B.: This is plain, that is, decoded, text.
2065  bool m_preserveSpaces = true;
2066  bool m_verbatim = false;
2067 };
2068 
2069 // ----------------------------------------------------------------------------
2070 
2081 class PCL_CLASS XMLCDATA : public XMLNode
2082 {
2083 public:
2084 
2092  XMLCDATA( const String& data = String() )
2093  : XMLNode( XMLNodeType::CDATA )
2094  , m_cdata( data )
2095  {
2096  }
2097 
2101  XMLCDATA( const XMLCDATA& ) = default;
2102 
2107  const String& CData() const
2108  {
2109  return m_cdata;
2110  }
2111 
2117  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2118 
2119 private:
2120 
2121  String m_cdata;
2122 };
2123 
2124 // ----------------------------------------------------------------------------
2125 
2138 {
2139 public:
2140 
2149  XMLProcessingInstructions( const String& target, const String& instructions )
2150  : XMLNode( XMLNodeType::ProcessingInstructions )
2151  , m_target( target )
2152  , m_instructions( instructions )
2153  {
2154  }
2155 
2160 
2164  const String& Target() const
2165  {
2166  return m_target;
2167  }
2168 
2172  const String& Instructions() const
2173  {
2174  return m_instructions;
2175  }
2176 
2182  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2183 
2184 private:
2185 
2186  String m_target;
2187  String m_instructions;
2188 };
2189 
2190 // ----------------------------------------------------------------------------
2191 
2202 class PCL_CLASS XMLComment : public XMLNode
2203 {
2204 public:
2205 
2214  XMLComment( const String& comment )
2215  : XMLNode( XMLNodeType::Comment )
2216  , m_comment( comment )
2217  {
2218  }
2219 
2223  XMLComment( const XMLComment& ) = default;
2224 
2228  const String& Comment() const
2229  {
2230  return m_comment;
2231  }
2232 
2238  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2239 
2240 private:
2241 
2242  String m_comment;
2243 };
2244 
2245 // ----------------------------------------------------------------------------
2246 
2259 class PCL_CLASS XMLUnknownElement : public XMLNode
2260 {
2261 public:
2262 
2267  XMLUnknownElement( const String& name, const String& parameters = String() )
2268  : XMLNode( XMLNodeType::Unknown )
2269  , m_name( name )
2270  , m_parameters( parameters )
2271  {
2272  }
2273 
2278 
2282  const String& Name() const
2283  {
2284  return m_name;
2285  }
2286 
2290  const String& Parameters() const
2291  {
2292  return m_parameters;
2293  }
2294 
2300  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2301 
2302 private:
2303 
2304  String m_name;
2305  String m_parameters;
2306 };
2307 
2308 // ----------------------------------------------------------------------------
2309 
2320 class PCL_CLASS XMLDeclaration : public XMLComponent
2321 {
2322 public:
2323 
2328  XMLDeclaration( const String& version = String(), const String& encoding = String(), bool standalone = false )
2329  : m_version( version )
2330  , m_encoding( encoding )
2331  , m_standalone( standalone )
2332  {
2333  }
2334 
2338  XMLDeclaration( const XMLDeclaration& ) = default;
2339 
2343  const String& Version() const
2344  {
2345  return m_version;
2346  }
2347 
2351  const String& DocumentEncoding() const
2352  {
2353  return m_encoding;
2354  }
2355 
2360  {
2361  return m_standalone;
2362  }
2363 
2369  bool IsDefined() const
2370  {
2371  return !m_version.IsEmpty();
2372  }
2373 
2383  void Serialize( IsoString& text ) const;
2384 
2385 private:
2386 
2387  String m_version;
2388  String m_encoding;
2389  bool m_standalone = false;
2390 };
2391 
2392 // ----------------------------------------------------------------------------
2393 
2405 class PCL_CLASS XMLDocTypeDeclaration : public XMLComponent
2406 {
2407 public:
2408 
2413  XMLDocTypeDeclaration( const String& name = String(), const String& definition = String() )
2414  : m_name( name )
2415  , m_definition( definition )
2416  {
2417  }
2418 
2423 
2427  const String& Name() const
2428  {
2429  return m_name;
2430  }
2431 
2435  const String& Definition() const
2436  {
2437  return m_definition;
2438  }
2439 
2445  bool IsDefined() const
2446  {
2447  return !m_name.IsEmpty();
2448  }
2449 
2457  void Serialize( IsoString& text ) const;
2458 
2459 private:
2460 
2461  String m_name;
2462  String m_definition;
2463 };
2464 
2465 // ----------------------------------------------------------------------------
2466 
2495 {
2500  {
2501  }
2502 
2507  virtual bool operator()( const XMLElement* parent, const String& name ) const = 0;
2508 
2519  virtual bool operator()( const XMLElement* parent, const String& name, const XMLAttributeList& attributes ) const
2520  {
2521  return true;
2522  }
2523 };
2524 
2525 // ----------------------------------------------------------------------------
2526 
2540 namespace XMLParserOption
2541 {
2542  enum mask_type
2543  {
2544  IgnoreComments = 0x00000001,
2545  IgnoreUnknownElements = 0x00000002,
2546  IgnoreStrayCharacters = 0x00000004,
2547  NormalizeTextSpaces = 0x00000008
2548  };
2549 }
2550 
2556 using XMLParserOptions = Flags<XMLParserOption::mask_type>;
2557 
2558 // ----------------------------------------------------------------------------
2559 
2640 class PCL_CLASS XMLDocument
2641 {
2642 public:
2643 
2647  using iterator = XMLNodeList::iterator;
2648 
2652  using const_iterator = XMLNodeList::const_iterator;
2653 
2658  using parser_option = XMLParserOption::mask_type;
2659 
2670  XMLDocument() = default;
2671 
2676  virtual ~XMLDocument()
2677  {
2678  m_nodes.Destroy();
2679  m_root = nullptr;
2680  RemoveElementFilter();
2681  }
2682 
2687  XMLDocument( const XMLDocument& ) = delete;
2688 
2693  XMLDocument& operator =( const XMLDocument& ) = delete;
2694 
2699  const XMLDeclaration& XML() const
2700  {
2701  return m_xml;
2702  }
2703 
2707  void SetXML( const XMLDeclaration& xml )
2708  {
2709  m_xml = xml;
2710  }
2711 
2716  void SetXML( const String& version = "1.0", const String& encoding = "UTF-8", bool standalone = false )
2717  {
2718  SetXML( XMLDeclaration( version, encoding, standalone ) );
2719  }
2720 
2726  {
2727  return m_docType;
2728  }
2729 
2734  void SetDocType( const XMLDocTypeDeclaration& docType )
2735  {
2736  m_docType = docType;
2737  }
2738 
2746  const XMLElement* RootElement() const
2747  {
2748  return m_root;
2749  }
2750 
2765  {
2766  XMLElement* root = m_root;
2767  m_nodes.RemovePointer( m_root );
2768  Clear();
2769  return root;
2770  }
2771 
2776  int NodeCount() const
2777  {
2778  return int( m_nodes.Length() );
2779  }
2780 
2785  bool IsEmpty() const
2786  {
2787  return m_nodes.IsEmpty();
2788  }
2789 
2795  const XMLNode& operator []( int i ) const
2796  {
2797  return m_nodes[i];
2798  }
2799 
2805  {
2806  return m_nodes.Begin();
2807  }
2808 
2814  {
2815  return m_nodes.End();
2816  }
2817 
2818 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
2823  {
2824  return Begin();
2825  }
2826 
2831  {
2832  return End();
2833  }
2834 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
2835 
2850  void AddNode( XMLNode* node );
2851 
2858  {
2859  AddNode( node );
2860  return *this;
2861  }
2862 
2876  void SetRootElement( XMLElement* element );
2877 
2889  void Clear();
2890 
2902  {
2903  XMLElement dum;
2904  m_nodes.Destroy( dum,
2905  [&]( const XMLNode& node, const XMLNode& )
2906  {
2907  if ( node.IsElement() )
2908  {
2909  const XMLElement& element = static_cast<const XMLElement&>( node );
2910  if ( !filter( nullptr, element.Name() ) ||
2911  !filter( nullptr, element.Name(), element.Attributes() ) )
2912  return true;
2913  }
2914  return false;
2915  } );
2916  }
2917 
2923  void RemoveElementsByName( const String& name, bool caseSensitive = true )
2924  {
2925  XMLElement dum;
2926  m_nodes.Destroy( dum,
2927  [&]( const XMLNode& node, const XMLNode& )
2928  {
2929  if ( node.IsElement() )
2930  {
2931  const XMLElement& element = static_cast<const XMLElement&>( node );
2932  if ( (caseSensitive ? element.Name().Compare( name ) : element.Name().CompareIC( name )) == 0 )
2933  return true;
2934  }
2935  return false;
2936  } );
2937  }
2938 
2949  {
2950  delete m_filter, m_filter = filter;
2951  }
2952 
2959  {
2960  SetElementFilter( nullptr );
2961  }
2962 
2968  void SetParserOption( parser_option option, bool on = true )
2969  {
2970  m_parserOptions.SetFlag( option, on );
2971  }
2972 
2979  {
2980  m_parserOptions = options;
2981  }
2982 
2988  {
2989  m_parserOptions.Clear();
2990  }
2991 
3004  void Parse( const String& text );
3005 
3025  bool IsAutoFormatting() const
3026  {
3027  return m_autoFormatting;
3028  }
3029 
3034  void EnableAutoFormatting( bool enable = true )
3035  {
3036  m_autoFormatting = enable;
3037  }
3038 
3043  void DisableAutoFormatting( bool disable = true )
3044  {
3045  EnableAutoFormatting( !disable );
3046  }
3047 
3057  int IndentSize() const
3058  {
3059  return m_indentSize;
3060  }
3061 
3085  void SetIndentSize( int indentSize )
3086  {
3087  m_indentSize = Range( indentSize, 0, 8 );
3088  }
3089 
3098  bool IsIndentTabs() const
3099  {
3100  return m_indentTabs;
3101  }
3102 
3107  void EnableIndentTabs( bool enable = true )
3108  {
3109  m_indentTabs = enable;
3110  }
3111 
3116  void DisableIndentTabs( bool disable = true )
3117  {
3118  EnableIndentTabs( !disable );
3119  }
3120 
3133  {
3134  return Serialize( false/*isHTML*/ );
3135  }
3136 
3151  {
3152  return Serialize( true/*isHTML*/ );
3153  }
3154 
3164  void SerializeToFile( const String& path ) const;
3165 
3176  void SerializeToFileAsHTML( const String& path ) const;
3177 
3178 private:
3179 
3180  XMLDeclaration m_xml;
3181  XMLDocTypeDeclaration m_docType;
3182  XMLNodeList m_nodes;
3183  XMLElement* m_root = nullptr;
3184  XMLElementFilter* m_filter = nullptr;
3185  XMLParserOptions m_parserOptions;
3186  XMLNodeLocation m_location;
3187  bool m_autoFormatting = false;
3188  bool m_indentTabs = false;
3189  int m_indentSize = 3;
3190 
3191  IsoString Serialize( bool isHTML ) const;
3192 };
3193 
3194 // ----------------------------------------------------------------------------
3195 
3196 } // pcl
3197 
3198 #endif // __PCL_XML_h
3199 
3200 // ----------------------------------------------------------------------------
3201 // EOF pcl/XML.h - Released 2024-06-18T15:48:54Z
A simple exception with an associated error message.
Definition: Exception.h:239
constexpr bool IsFlagSet(enum_type e) const
Definition: Flags.h:244
void SetFlag(enum_type e, bool on=true)
Definition: Flags.h:252
typename FlagType< std::is_unsigned< enum_type >::value >::type flag_type
Definition: Flags.h:99
bool IsEmpty() const noexcept
Definition: String.h:818
iterator Begin()
Definition: String.h:976
iterator End()
Definition: String.h:1006
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5425
Unicode (UTF-16) string.
Definition: String.h:8113
string_base::const_iterator const_iterator
Definition: String.h:8169
Dynamic list of XML element attributes.
Definition: XML.h:862
void SetAttribute(const String &name, const String &value)
Definition: XML.h:1004
const_iterator begin() const
Definition: XML.h:955
bool IsEmpty() const
Definition: XML.h:918
XMLAttributeList(const String &text)
Definition: XML.h:892
XMLAttributeList()=default
const_iterator end() const
Definition: XML.h:963
const_iterator End() const
Definition: XML.h:946
void SetAttribute(const XMLAttribute &attribute)
Definition: XML.h:1021
bool HasAttribute(const String &name) const
Definition: XML.h:973
String AttributeValue(const String &name) const
Definition: XML.h:983
void RemoveAttribute(const String &name)
Definition: XML.h:1081
void Parse(const String &text)
XMLAttributeList(const XMLAttributeList &)=default
void SetAttributes(const XMLAttributeList &list)
Definition: XML.h:1059
void Serialize(IsoString &text) const
const_iterator Begin() const
Definition: XML.h:937
int Length() const
Definition: XML.h:910
XML element attribute
Definition: XML.h:748
void SetValue(const String &text)
Definition: XML.h:800
XMLAttribute(const XMLAttribute &)=default
const String & Value() const
Definition: XML.h:792
XMLAttribute()=default
XMLAttribute(const String &name, const String &value=String())
Definition: XML.h:770
String EncodedValue() const
Definition: XML.h:810
const String & Name() const
Definition: XML.h:784
XML CDATA section
Definition: XML.h:2082
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & CData() const
Definition: XML.h:2107
XMLCDATA(const XMLCDATA &)=default
XML comment section
Definition: XML.h:2203
XMLComment(const String &comment)
Definition: XML.h:2214
const String & Comment() const
Definition: XML.h:2228
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
XMLComment(const XMLComment &)=default
Root base class of all XML document components.
Definition: XML.h:335
XMLComponent()=default
bool IsTopLevel() const
Definition: XML.h:369
XMLComponent(const XMLComponent &)=default
virtual ~XMLComponent()
Definition: XML.h:352
XMLElement * ParentElement() const
Definition: XML.h:360
XML declaration
Definition: XML.h:2321
bool IsDefined() const
Definition: XML.h:2369
bool IsStandaloneDocument() const
Definition: XML.h:2359
XMLDeclaration(const String &version=String(), const String &encoding=String(), bool standalone=false)
Definition: XML.h:2328
void Serialize(IsoString &text) const
const String & DocumentEncoding() const
Definition: XML.h:2351
const String & Version() const
Definition: XML.h:2343
XMLDeclaration(const XMLDeclaration &)=default
XML DOCTYPE declaration
Definition: XML.h:2406
XMLDocTypeDeclaration(const String &name=String(), const String &definition=String())
Definition: XML.h:2413
const String & Definition() const
Definition: XML.h:2435
bool IsDefined() const
Definition: XML.h:2445
const String & Name() const
Definition: XML.h:2427
XMLDocTypeDeclaration(const XMLDocTypeDeclaration &)=default
void Serialize(IsoString &text) const
XML document parsing and generation
Definition: XML.h:2641
bool IsEmpty() const
Definition: XML.h:2785
void SerializeToFileAsHTML(const String &path) const
IsoString SerializeAsHTML() const
Definition: XML.h:3150
XMLNodeList::const_iterator const_iterator
Definition: XML.h:2652
const XMLDeclaration & XML() const
Definition: XML.h:2699
bool IsIndentTabs() const
Definition: XML.h:3098
XMLElement * ReleaseRootElement()
Definition: XML.h:2764
void SetParserOption(parser_option option, bool on=true)
Definition: XML.h:2968
const XMLDocTypeDeclaration & DocType() const
Definition: XML.h:2725
int IndentSize() const
Definition: XML.h:3057
XMLDocument(const XMLDocument &)=delete
void SetRootElement(XMLElement *element)
virtual ~XMLDocument()
Definition: XML.h:2676
XMLNodeList::iterator iterator
Definition: XML.h:2647
void RemoveElementsByName(const String &name, bool caseSensitive=true)
Definition: XML.h:2923
const_iterator Begin() const
Definition: XML.h:2804
const_iterator begin() const
Definition: XML.h:2822
void EnableIndentTabs(bool enable=true)
Definition: XML.h:3107
void DisableIndentTabs(bool disable=true)
Definition: XML.h:3116
void EnableAutoFormatting(bool enable=true)
Definition: XML.h:3034
void SerializeToFile(const String &path) const
const_iterator End() const
Definition: XML.h:2813
const XMLElement * RootElement() const
Definition: XML.h:2746
bool IsAutoFormatting() const
Definition: XML.h:3025
void SetXML(const XMLDeclaration &xml)
Definition: XML.h:2707
void RemoveElementsByFilter(const XMLElementFilter &filter)
Definition: XML.h:2901
void SetElementFilter(XMLElementFilter *filter)
Definition: XML.h:2948
void SetXML(const String &version="1.0", const String &encoding="UTF-8", bool standalone=false)
Definition: XML.h:2716
void DisableAutoFormatting(bool disable=true)
Definition: XML.h:3043
XMLDocument()=default
void SetDocType(const XMLDocTypeDeclaration &docType)
Definition: XML.h:2734
IsoString Serialize() const
Definition: XML.h:3132
void ClearParserOptions()
Definition: XML.h:2987
void SetParserOptions(XMLParserOptions options)
Definition: XML.h:2978
void Parse(const String &text)
int NodeCount() const
Definition: XML.h:2776
const_iterator end() const
Definition: XML.h:2830
void RemoveElementFilter()
Definition: XML.h:2958
void AddNode(XMLNode *node)
void SetIndentSize(int indentSize)
Definition: XML.h:3085
XML element
Definition: XML.h:1162
bool HasChildNodeThat(UP u, bool recursive=false) const
Definition: XML.h:1793
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
iterator begin()
Definition: XML.h:1566
void SortAttributes()
Definition: XML.h:1391
bool HasAttribute(const String &name) const
Definition: XML.h:1277
int ChildCount() const
Definition: XML.h:1444
const_iterator ConstBegin() const
Definition: XML.h:1548
XMLElement(const String &name, const XMLAttributeList &attributes=XMLAttributeList())
Definition: XML.h:1193
void SerializeAsHTML(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
String Text() const
const_iterator End() const
Definition: XML.h:1501
void SetAttribute(const XMLAttribute &attribute)
Definition: XML.h:1319
bool IsRootElement() const
Definition: XML.h:1244
~XMLElement() override
Definition: XML.h:1229
String AttributeValue(const String &name) const
Definition: XML.h:1287
iterator end()
Definition: XML.h:1574
bool HasElements() const
Definition: XML.h:1585
void SetAttribute(const String &name, const String &value)
Definition: XML.h:1307
bool HasAttributes() const
Definition: XML.h:1268
XMLNodeList::iterator iterator
Definition: XML.h:1168
bool HasChildElementWithName(const String &name, bool recursive=false) const
Definition: XML.h:1703
child_element_list ChildElementsByName(const String &name, bool recursive=false) const
Definition: XML.h:1688
void SetAttributes(const XMLAttributeList &list)
Definition: XML.h:1352
XMLElement(const XMLElement &)=delete
const XMLNode & Last() const
Definition: XML.h:1483
const_iterator end() const
Definition: XML.h:1518
XMLNodeList::const_iterator const_iterator
Definition: XML.h:1173
bool HasComments() const
Definition: XML.h:1619
void AddChildNode(XMLNode *node)
Definition: XML.h:1813
iterator End()
Definition: XML.h:1539
XMLNodeList ChildNodesThat(UP u, bool recursive=false) const
Definition: XML.h:1777
void RemoveAttribute(const String &name)
Definition: XML.h:1374
void ParseAttributes(const String &text)
Definition: XML.h:1419
iterator Begin()
Definition: XML.h:1530
XMLNodeList ChildNodesByType(XMLNodeTypes types, bool recursive=false) const
Definition: XML.h:1742
void DestroyChildNodes()
Definition: XML.h:1875
void SerializeAttributes(IsoString &text) const
Definition: XML.h:1436
XMLNodeList ReleaseChildNodes()
Definition: XML.h:1890
bool HasCDATA() const
Definition: XML.h:1601
void ClearAttributes()
Definition: XML.h:1382
const_iterator begin() const
Definition: XML.h:1510
const_iterator Begin() const
Definition: XML.h:1492
XMLElement(XMLElement &parent, const String &name, const XMLAttributeList &attributes=XMLAttributeList())
Definition: XML.h:1205
void SortAttributes(BP p)
Definition: XML.h:1403
bool HasProcessingInstructions() const
Definition: XML.h:1610
const_iterator ConstEnd() const
Definition: XML.h:1557
bool IsEmpty() const
Definition: XML.h:1453
const XMLNode & First() const
Definition: XML.h:1473
void AddChildNodes(XMLNodeList &nodes)
Definition: XML.h:1840
ReferenceArray< XMLElement > child_element_list
Definition: XML.h:1179
XMLAttributeList Attributes() const
Definition: XML.h:1260
bool HasText() const
Definition: XML.h:1593
child_element_list ChildElements(bool recursive=false) const
Definition: XML.h:1655
const String & Name() const
Definition: XML.h:1252
Abstract base class of all XML document node classes.
Definition: XML.h:507
bool IsText() const
Definition: XML.h:575
bool IsElement() const
Definition: XML.h:566
~XMLNode() override
Definition: XML.h:542
XMLNode(const XMLNode &x)
Definition: XML.h:533
virtual void SerializeAsHTML(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const
Definition: XML.h:636
virtual void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const =0
const XMLNodeLocation & Location() const
Definition: XML.h:592
virtual bool NLAfter(const XMLNode &previous) const
bool IsComment() const
Definition: XML.h:584
XMLNode(node_type type)
Definition: XML.h:521
bool IsChildNode() const
Definition: XML.h:549
node_type NodeType() const
Definition: XML.h:557
XML parsing error with automatic text location information generation
Definition: XML.h:683
XMLParseError(const XMLNode &node, const String &whileDoing, const String &whatHappened)
Definition: XML.h:702
XMLParseError(const XMLNodeLocation &where, const String &whileDoing, const String &whatHappened)
Definition: XML.h:723
XMLParseError(const XMLParseError &)=default
A collection of XML document parsing options.
XML processing instructions
Definition: XML.h:2138
XMLProcessingInstructions(const String &target, const String &instructions)
Definition: XML.h:2149
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & Target() const
Definition: XML.h:2164
const String & Instructions() const
Definition: XML.h:2172
XMLProcessingInstructions(const XMLProcessingInstructions &)=default
XML text block
Definition: XML.h:1952
XMLText(const String &text, bool preserveSpaces=true, bool verbatim=false)
Definition: XML.h:1980
XMLText(const XMLText &)=default
bool IsPreserveSpaces() const
Definition: XML.h:2006
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
bool NLAfter(const XMLNode &previous) const override
Definition: XML.h:2057
const String & Text() const
Definition: XML.h:1997
String SpaceTransformedText(bool collapse, bool trim) const
Definition: XML.h:2029
String EncodedText() const
Definition: XML.h:2016
Unsupported or invalid XML element.
Definition: XML.h:2260
XMLUnknownElement(const XMLUnknownElement &)=default
XMLUnknownElement(const String &name, const String &parameters=String())
Definition: XML.h:2267
const String & Parameters() const
Definition: XML.h:2290
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & Name() const
Definition: XML.h:2282
Utility functions and data for XML document parsing and generation.
Definition: XML.h:85
static String TrimmedSpaces(String::const_iterator i, String::const_iterator j)
static String TrimmedSpaces(const String &text)
static String DecodedText(String::const_iterator i, String::const_iterator j)
static String EncodedText(String::const_iterator i, String::const_iterator j, bool apos=true)
Definition: XML.h:278
static String EncodedText(const String &text, bool apos=true)
static bool IsValidName(const String &name)
Definition: XML.h:207
static String CollapsedSpaces(const String &text)
static bool IsWhiteSpaceChar(T c)
Definition: XML.h:117
static String ReferenceValue(const String &reference)
Definition: XML.h:316
static String DecodedText(const String &text)
XML(const XML &)=delete
~XML()=delete
static bool IsSpaceChar(T c)
Definition: XML.h:138
static bool IsNameStartChar(T c)
Definition: XML.h:149
XML()=delete
static String CollapsedSpaces(String::const_iterator i, String::const_iterator j)
static bool IsRestrictedChar(T c)
Definition: XML.h:192
static bool IsNameChar(T c)
Definition: XML.h:175
static bool IsLineBreakChar(T c)
Definition: XML.h:127
static String ReferenceValue(String::const_iterator i, String::const_iterator j)
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
Definition: Array.h:2295
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2267
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2278
signed long long int64
Definition: Defs.h:676
unsigned int uint32
Definition: Defs.h:666
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
Definition: Utility.h:190
String AsString(mask_type type)
PCL root namespace.
Definition: AbstractImage.h:77
A functional class for filtering XML elements.
Definition: XML.h:2495
virtual ~XMLElementFilter()
Definition: XML.h:2499
virtual bool operator()(const XMLElement *parent, const String &name) const =0
virtual bool operator()(const XMLElement *parent, const String &name, const XMLAttributeList &attributes) const
Definition: XML.h:2519
Source code location of a parsed XML document node.
Definition: XML.h:437
String ToString() const
XMLNodeLocation(const XMLNodeLocation &)=default
XMLNodeLocation(int line_, int column_)
Definition: XML.h:467
XMLNodeLocation()=default