PCL
XML.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.5
6 // ----------------------------------------------------------------------------
7 // pcl/XML.h - Released 2024-12-28T16:53:48Z
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& operator =( const XMLNode& x )
543  {
544  m_type = x.NodeType();
545  m_location = x.m_location;
546  return *this;
547  }
548 
552  ~XMLNode() override
553  {
554  }
555 
559  bool IsChildNode() const
560  {
561  return m_type.IsFlagSet( XMLNodeType::ChildNode );
562  }
563 
567  node_type NodeType() const
568  {
569  return static_cast<node_type>( XMLNodeTypes::flag_type( m_type & unsigned( ~XMLNodeType::ChildNode ) ) );
570  }
571 
576  bool IsElement() const
577  {
578  return NodeType() == XMLNodeType::Element;
579  }
580 
585  bool IsText() const
586  {
587  return NodeType() == XMLNodeType::Text;
588  }
589 
594  bool IsComment() const
595  {
596  return NodeType() == XMLNodeType::Comment;
597  }
598 
602  const XMLNodeLocation& Location() const
603  {
604  return m_location;
605  }
606 
610  virtual XMLNode* Clone() const = 0;
611 
637  virtual void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const = 0;
638 
651  virtual void SerializeAsHTML( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const
652  {
653  Serialize( text, autoFormat, indentChar, indentSize, level );
654  }
655 
660  virtual bool NLAfter( const XMLNode& previous ) const;
661 
662 private:
663 
664  XMLNodeTypes m_type;
665  XMLNodeLocation m_location;
666 
667  friend class XMLDocument;
668  friend class XMLElement;
669 };
670 
682 
683 // ----------------------------------------------------------------------------
684 
697 class PCL_CLASS XMLParseError : public Error
698 {
699 public:
700 
717  XMLParseError( const XMLNode& node, const String& whileDoing, const String& whatHappened )
718  : Error( whileDoing + node.Location().ToString() + ": " + whatHappened )
719  {
720  }
721 
738  XMLParseError( const XMLNodeLocation& where, const String& whileDoing, const String& whatHappened )
739  : Error( whileDoing + where.ToString() + ": " + whatHappened )
740  {
741  }
742 
746  XMLParseError( const XMLParseError& ) = default;
747 };
748 
749 // ----------------------------------------------------------------------------
750 
762 class PCL_CLASS XMLAttribute : public XMLComponent
763 {
764 public:
765 
770  XMLAttribute() = default;
771 
785  XMLAttribute( const String& name, const String& value = String() )
786  : m_name( name )
787  , m_value( value )
788  {
789  }
790 
794  XMLAttribute( const XMLAttribute& ) = default;
795 
799  const String& Name() const
800  {
801  return m_name;
802  }
803 
807  const String& Value() const
808  {
809  return m_value;
810  }
811 
815  void SetValue( const String& text )
816  {
817  m_value = text;
818  }
819 
826  {
827  return XML::EncodedText( m_value, false/*apos*/ );
828  }
829 
837  bool operator ==( const XMLAttribute& x ) const
838  {
839  return m_name == x.m_name;
840  }
841 
849  bool operator <( const XMLAttribute& x ) const
850  {
851  return m_name < x.m_name;
852  }
853 
854 private:
855 
856  String m_name;
857  String m_value;
858 };
859 
860 // ----------------------------------------------------------------------------
861 
876 class PCL_CLASS XMLAttributeList
877 {
878 public:
879 
885 
890 
895 
907  XMLAttributeList( const String& text )
908  {
909  Parse( text );
910  }
911 
915  XMLAttributeList() = default;
916 
920  XMLAttributeList( const XMLAttributeList& ) = default;
921 
925  int Length() const
926  {
927  return int( m_list.Length() );
928  }
929 
933  bool IsEmpty() const
934  {
935  return m_list.IsEmpty();
936  }
937 
943  const XMLAttribute& operator []( int i ) const
944  {
945  return m_list[i];
946  }
947 
953  {
954  return m_list.Begin();
955  }
956 
962  {
963  return m_list.End();
964  }
965 
966 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
971  {
972  return Begin();
973  }
974 
979  {
980  return End();
981  }
982 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
983 
988  bool HasAttribute( const String& name ) const
989  {
990  return m_list.Contains( name );
991  }
992 
998  String AttributeValue( const String& name ) const
999  {
1000  const_iterator a = m_list.Search( name );
1001  return (a != m_list.End()) ? a->Value() : String();
1002  }
1003 
1019  void SetAttribute( const String& name, const String& value )
1020  {
1021  if ( !name.IsEmpty() )
1022  {
1023  iterator a = m_list.Search( name );
1024  if ( a == m_list.End() )
1025  m_list.Add( XMLAttribute( name, value ) );
1026  else
1027  a->SetValue( value );
1028  }
1029  }
1030 
1036  void SetAttribute( const XMLAttribute& attribute )
1037  {
1038  if ( !attribute.Name().IsEmpty() )
1039  {
1040  iterator a = m_list.Search( attribute );
1041  if ( a == m_list.End() )
1042  m_list.Add( attribute );
1043  else
1044  *a = attribute;
1045  }
1046  }
1047 
1054  {
1055  SetAttribute( attribute );
1056  return *this;
1057  }
1058 
1074  void SetAttributes( const XMLAttributeList& list )
1075  {
1076  for ( auto a : list )
1077  SetAttribute( a );
1078  }
1079 
1086  {
1087  SetAttributes( list );
1088  return *this;
1089  }
1090 
1096  void RemoveAttribute( const String& name )
1097  {
1098  iterator a = m_list.Search( name );
1099  if ( a != m_list.End() )
1100  m_list.Remove( a );
1101  }
1102 
1107  void Clear()
1108  {
1109  m_list.Clear();
1110  }
1111 
1116  void Sort()
1117  {
1118  m_list.Sort();
1119  }
1120 
1142  void Parse( const String& text );
1143 
1154  void Serialize( IsoString& text ) const;
1155 
1156 private:
1157 
1158  list_implementation m_list;
1159 };
1160 
1161 // ----------------------------------------------------------------------------
1162 
1176 class PCL_CLASS XMLElement : public XMLNode
1177 {
1178 public:
1179 
1183  using iterator = XMLNodeList::iterator;
1184 
1188  using const_iterator = XMLNodeList::const_iterator;
1189 
1195 
1200  : XMLNode( XMLNodeType::Element )
1201  {
1202  }
1203 
1208  XMLElement( const String& name, const XMLAttributeList& attributes = XMLAttributeList() )
1209  : XMLNode( XMLNodeType::Element )
1210  , m_name( name )
1211  , m_attributes( attributes )
1212  {
1213  }
1214 
1220  XMLElement( XMLElement& parent, const String& name, const XMLAttributeList& attributes = XMLAttributeList() )
1221  : XMLNode( XMLNodeType::Element )
1222  , m_name( name )
1223  , m_attributes( attributes )
1224  {
1225  parent.AddChildNode( this );
1226  }
1227 
1232  : XMLNode( x )
1233  , m_name( x.m_name )
1234  , m_attributes( x.m_attributes )
1235  , m_childTypes( x.m_childTypes )
1236  {
1237  for ( const XMLNode& node : x.m_childNodes )
1238  m_childNodes << node.Clone();
1239  }
1240 
1244  XMLElement& operator =( const XMLElement& x )
1245  {
1246  (void)XMLNode::operator =( x );
1247  m_name = x.m_name;
1248  m_attributes = x.m_attributes;
1249  m_childTypes = x.m_childTypes;
1250  m_childNodes.Destroy();
1251  for ( const XMLNode& node : x.m_childNodes )
1252  m_childNodes << node.Clone();
1253  return *this;
1254  }
1255 
1260  ~XMLElement() override
1261  {
1262  DestroyChildNodes();
1263  }
1264 
1275  bool IsRootElement() const
1276  {
1277  return ParentElement() == nullptr;
1278  }
1279 
1283  const String& Name() const
1284  {
1285  return m_name;
1286  }
1287 
1292  {
1293  return m_attributes;
1294  }
1295 
1299  bool HasAttributes() const
1300  {
1301  return !m_attributes.IsEmpty();
1302  }
1303 
1308  bool HasAttribute( const String& name ) const
1309  {
1310  return m_attributes.HasAttribute( name );
1311  }
1312 
1318  String AttributeValue( const String& name ) const
1319  {
1320  return m_attributes.AttributeValue( name );
1321  }
1322 
1338  void SetAttribute( const String& name, const String& value )
1339  {
1340  XMLAttribute a( name, value );
1341  a.m_parent = this;
1342  m_attributes.SetAttribute( a );
1343  }
1344 
1350  void SetAttribute( const XMLAttribute& attribute )
1351  {
1352  XMLAttribute a( attribute );
1353  a.m_parent = this;
1354  m_attributes.SetAttribute( a );
1355  }
1356 
1362  XMLElement& operator <<( const XMLAttribute& attribute )
1363  {
1364  SetAttribute( attribute );
1365  return *this;
1366  }
1367 
1383  void SetAttributes( const XMLAttributeList& list )
1384  {
1385  for ( auto a : list )
1386  SetAttribute( a );
1387  }
1388 
1395  {
1396  SetAttributes( list );
1397  return *this;
1398  }
1399 
1405  void RemoveAttribute( const String& name )
1406  {
1407  m_attributes.RemoveAttribute( name );
1408  }
1409 
1414  {
1415  m_attributes.Clear();
1416  }
1417 
1423  {
1424  m_attributes.Sort();
1425  }
1426 
1433  template <class BP>
1434  void SortAttributes( BP p )
1435  {
1436  m_attributes.Sort( p );
1437  }
1438 
1450  void ParseAttributes( const String& text )
1451  {
1452  XMLAttributeList list( text );
1453  ClearAttributes();
1454  SetAttributes( list );
1455  }
1456 
1467  void SerializeAttributes( IsoString& text ) const
1468  {
1469  m_attributes.Serialize( text );
1470  }
1471 
1475  int ChildCount() const
1476  {
1477  return int( m_childNodes.Length() );
1478  }
1479 
1484  bool IsEmpty() const
1485  {
1486  return m_childNodes.IsEmpty();
1487  }
1488 
1494  const XMLNode& operator []( int i ) const
1495  {
1496  return m_childNodes[i];
1497  }
1498 
1504  const XMLNode& First() const
1505  {
1506  return m_childNodes.First();
1507  }
1508 
1514  const XMLNode& Last() const
1515  {
1516  return m_childNodes.Last();
1517  }
1518 
1524  {
1525  return m_childNodes.Begin();
1526  }
1527 
1533  {
1534  return m_childNodes.End();
1535  }
1536 
1537 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1542  {
1543  return Begin();
1544  }
1545 
1550  {
1551  return End();
1552  }
1553 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1554 
1555 #ifndef __PCL_NO_MUTABLE_XML_ELEMENT_ITERATORS
1556 
1562  {
1563  return m_childNodes.Begin();
1564  }
1565 
1571  {
1572  return m_childNodes.End();
1573  }
1574 
1580  {
1581  return m_childNodes.ConstBegin();
1582  }
1583 
1589  {
1590  return m_childNodes.ConstEnd();
1591  }
1592 
1593 # ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1598  {
1599  return Begin();
1600  }
1601 
1606  {
1607  return End();
1608  }
1609 # endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1610 
1611 #endif // !__PCL_NO_MUTABLE_XML_ELEMENT_ITERATORS
1612 
1616  bool HasElements() const
1617  {
1618  return m_childTypes.IsFlagSet( XMLNodeType::Element );
1619  }
1620 
1624  bool HasText() const
1625  {
1626  return m_childTypes.IsFlagSet( XMLNodeType::Text );
1627  }
1628 
1632  bool HasCDATA() const
1633  {
1634  return m_childTypes.IsFlagSet( XMLNodeType::CDATA );
1635  }
1636 
1642  {
1643  return m_childTypes.IsFlagSet( XMLNodeType::ProcessingInstructions );
1644  }
1645 
1650  bool HasComments() const
1651  {
1652  return m_childTypes.IsFlagSet( XMLNodeType::Comment );
1653  }
1654 
1662  String Text() const;
1663 
1667  void GetChildElements( child_element_list& list, bool recursive ) const
1668  {
1669  for ( const XMLNode& node : m_childNodes )
1670  if ( node.IsElement() )
1671  {
1672  const XMLElement& element = static_cast<const XMLElement&>( node );
1673  list << &element;
1674  if ( recursive )
1675  element.GetChildElements( list, recursive );
1676  }
1677  }
1678 
1686  child_element_list ChildElements( bool recursive = false ) const
1687  {
1688  child_element_list list;
1689  GetChildElements( list, recursive );
1690  return list;
1691  }
1692 
1696  void GetChildElementsByName( child_element_list& list, const String& name, bool recursive ) const
1697  {
1698  for ( const XMLNode& node : m_childNodes )
1699  if ( node.IsElement() )
1700  {
1701  const XMLElement& element = static_cast<const XMLElement&>( node );
1702  if ( element.Name() == name )
1703  {
1704  list << &element;
1705  if ( recursive )
1706  element.GetChildElementsByName( list, name, recursive );
1707  }
1708  }
1709  }
1710 
1719  child_element_list ChildElementsByName( const String& name, bool recursive = false ) const
1720  {
1721  child_element_list list;
1722  GetChildElementsByName( list, name, recursive );
1723  return list;
1724  }
1725 
1734  bool HasChildElementWithName( const String& name, bool recursive = false ) const
1735  {
1736  for ( const XMLNode& node : m_childNodes )
1737  if ( node.IsElement() )
1738  {
1739  const XMLElement& element = static_cast<const XMLElement&>( node );
1740  if ( element.Name() == name )
1741  return true;
1742  if ( recursive )
1743  if ( element.HasChildElementWithName( name, recursive ) )
1744  return true;
1745  }
1746  return false;
1747  }
1748 
1752  void GetChildNodesByType( XMLNodeList& list, XMLNodeTypes types, bool recursive ) const
1753  {
1754  for ( const XMLNode& node : m_childNodes )
1755  if ( types.IsFlagSet( node.NodeType() ) )
1756  {
1757  list << &node;
1758  if ( recursive )
1759  if ( node.IsElement() )
1760  static_cast<const XMLElement&>( node ).GetChildNodesByType( list, types, recursive );
1761  }
1762  }
1763 
1773  XMLNodeList ChildNodesByType( XMLNodeTypes types, bool recursive = false ) const
1774  {
1775  XMLNodeList list;
1776  GetChildNodesByType( list, types, recursive );
1777  return list;
1778  }
1779 
1783  template <class UP>
1784  void GetChildNodesThat( XMLNodeList& list, UP u, bool recursive ) const
1785  {
1786  for ( const XMLNode& node : m_childNodes )
1787  if ( u( node ) )
1788  {
1789  list << &node;
1790  if ( recursive )
1791  if ( node.IsElement() )
1792  static_cast<const XMLElement&>( node ).GetChildNodesThat( list, u, recursive );
1793  }
1794  }
1795 
1807  template <class UP>
1808  XMLNodeList ChildNodesThat( UP u, bool recursive = false ) const
1809  {
1810  XMLNodeList list;
1811  GetChildNodesThat( list, u, recursive );
1812  return list;
1813  }
1814 
1823  template <class UP>
1824  bool HasChildNodeThat( UP u, bool recursive = false ) const
1825  {
1826  for ( const XMLNode& node : m_childNodes )
1827  {
1828  if ( u( node ) )
1829  return true;
1830  if ( recursive )
1831  if ( node.IsElement() )
1832  if ( static_cast<const XMLElement&>( node ).HasChildNodeThat( u, recursive ) )
1833  return true;
1834  }
1835  return false;
1836  }
1837 
1844  void AddChildNode( XMLNode* node )
1845  {
1846  m_childNodes << node;
1847  node->m_parent = this;
1848  node->m_type.SetFlag( XMLNodeType::ChildNode );
1849  m_childTypes.SetFlag( node->NodeType() );
1850  }
1851 
1859  {
1860  AddChildNode( node );
1861  return *this;
1862  }
1863 
1872  {
1873  for ( XMLNode& node : nodes )
1874  AddChildNode( &node );
1875  }
1876 
1884  {
1885  AddChildNodes( nodes );
1886  return *this;
1887  }
1888 
1896  void AddChildNode( XMLNode* node, const XMLNodeLocation& location )
1897  {
1898  node->m_location = location;
1899  AddChildNode( node );
1900  }
1901 
1907  {
1908  m_childNodes.Destroy();
1909  m_childTypes = XMLNodeType::Undefined;
1910  }
1911 
1922  {
1923  XMLNodeList nodes = m_childNodes;
1924  m_childNodes.Clear();
1925  m_childTypes = XMLNodeType::Undefined;
1926  return nodes;
1927  }
1928 
1932  XMLNode* Clone() const override
1933  {
1934  return new XMLElement( *this );
1935  }
1936 
1944  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
1945 
1954  void SerializeAsHTML( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
1955 
1956 private:
1957 
1958  String m_name;
1959  XMLAttributeList m_attributes;
1960  XMLNodeList m_childNodes;
1961  XMLNodeTypes m_childTypes = XMLNodeType::Undefined;
1962 };
1963 
1964 // ----------------------------------------------------------------------------
1965 
1977 
1978 // ----------------------------------------------------------------------------
1979 
1990 class PCL_CLASS XMLText : public XMLNode
1991 {
1992 public:
1993 
2019  XMLText( const String& text, bool preserveSpaces = true, bool verbatim = false )
2020  : XMLNode( XMLNodeType::Text )
2021  , m_text( preserveSpaces ? text : XML::CollapsedSpaces( XML::TrimmedSpaces( text ) ) )
2022  , m_preserveSpaces( preserveSpaces )
2023  , m_verbatim( verbatim )
2024  {
2025  }
2026 
2030  XMLText( const XMLText& ) = default;
2031 
2035  XMLText& operator =( const XMLText& ) = default;
2036 
2041  const String& Text() const
2042  {
2043  return m_text;
2044  }
2045 
2050  bool IsPreserveSpaces() const
2051  {
2052  return m_preserveSpaces;
2053  }
2054 
2061  {
2062  return XML::EncodedText( m_text );
2063  }
2064 
2073  String SpaceTransformedText( bool collapse, bool trim ) const
2074  {
2075  String text = m_text;
2076  if ( trim )
2077  text = XML::TrimmedSpaces( text );
2078  if ( collapse )
2079  text = XML::CollapsedSpaces( text );
2080  return text;
2081  }
2082 
2086  XMLNode* Clone() const override
2087  {
2088  return new XMLText( *this );
2089  }
2090 
2098  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2099 
2109  bool NLAfter( const XMLNode& previous ) const override
2110  {
2111  return !m_preserveSpaces;
2112  }
2113 
2114 private:
2115 
2116  String m_text; // N.B.: This is plain, that is, decoded, text.
2117  bool m_preserveSpaces = true;
2118  bool m_verbatim = false;
2119 };
2120 
2121 // ----------------------------------------------------------------------------
2122 
2133 class PCL_CLASS XMLCDATA : public XMLNode
2134 {
2135 public:
2136 
2144  XMLCDATA( const String& data = String() )
2145  : XMLNode( XMLNodeType::CDATA )
2146  , m_cdata( data )
2147  {
2148  }
2149 
2153  XMLCDATA( const XMLCDATA& ) = default;
2154 
2158  XMLCDATA& operator =( const XMLCDATA& ) = default;
2159 
2164  const String& CData() const
2165  {
2166  return m_cdata;
2167  }
2168 
2172  XMLNode* Clone() const override
2173  {
2174  return new XMLCDATA( *this );
2175  }
2176 
2182  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2183 
2184 private:
2185 
2186  String m_cdata;
2187 };
2188 
2189 // ----------------------------------------------------------------------------
2190 
2203 {
2204 public:
2205 
2214  XMLProcessingInstructions( const String& target, const String& instructions )
2215  : XMLNode( XMLNodeType::ProcessingInstructions )
2216  , m_target( target )
2217  , m_instructions( instructions )
2218  {
2219  }
2220 
2225 
2230 
2234  const String& Target() const
2235  {
2236  return m_target;
2237  }
2238 
2242  const String& Instructions() const
2243  {
2244  return m_instructions;
2245  }
2246 
2250  XMLNode* Clone() const override
2251  {
2252  return new XMLProcessingInstructions( *this );
2253  }
2254 
2260  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2261 
2262 private:
2263 
2264  String m_target;
2265  String m_instructions;
2266 };
2267 
2268 // ----------------------------------------------------------------------------
2269 
2280 class PCL_CLASS XMLComment : public XMLNode
2281 {
2282 public:
2283 
2292  XMLComment( const String& comment )
2293  : XMLNode( XMLNodeType::Comment )
2294  , m_comment( comment )
2295  {
2296  }
2297 
2301  XMLComment( const XMLComment& ) = default;
2302 
2306  XMLComment& operator =( const XMLComment& ) = default;
2307 
2311  const String& Comment() const
2312  {
2313  return m_comment;
2314  }
2315 
2319  XMLNode* Clone() const override
2320  {
2321  return new XMLComment( *this );
2322  }
2323 
2329  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2330 
2331 private:
2332 
2333  String m_comment;
2334 };
2335 
2336 // ----------------------------------------------------------------------------
2337 
2350 class PCL_CLASS XMLUnknownElement : public XMLNode
2351 {
2352 public:
2353 
2358  XMLUnknownElement( const String& name, const String& parameters = String() )
2359  : XMLNode( XMLNodeType::Unknown )
2360  , m_name( name )
2361  , m_parameters( parameters )
2362  {
2363  }
2364 
2369 
2373  XMLUnknownElement& operator =( const XMLUnknownElement& ) = default;
2374 
2378  const String& Name() const
2379  {
2380  return m_name;
2381  }
2382 
2386  const String& Parameters() const
2387  {
2388  return m_parameters;
2389  }
2390 
2394  XMLNode* Clone() const override
2395  {
2396  return new XMLUnknownElement( *this );
2397  }
2398 
2404  void Serialize( IsoString& text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level ) const override;
2405 
2406 private:
2407 
2408  String m_name;
2409  String m_parameters;
2410 };
2411 
2412 // ----------------------------------------------------------------------------
2413 
2424 class PCL_CLASS XMLDeclaration : public XMLComponent
2425 {
2426 public:
2427 
2432  XMLDeclaration( const String& version = String(), const String& encoding = String(), bool standalone = false )
2433  : m_version( version )
2434  , m_encoding( encoding )
2435  , m_standalone( standalone )
2436  {
2437  }
2438 
2442  XMLDeclaration( const XMLDeclaration& ) = default;
2443 
2447  const String& Version() const
2448  {
2449  return m_version;
2450  }
2451 
2455  const String& DocumentEncoding() const
2456  {
2457  return m_encoding;
2458  }
2459 
2464  {
2465  return m_standalone;
2466  }
2467 
2473  bool IsDefined() const
2474  {
2475  return !m_version.IsEmpty();
2476  }
2477 
2487  void Serialize( IsoString& text ) const;
2488 
2489 private:
2490 
2491  String m_version;
2492  String m_encoding;
2493  bool m_standalone = false;
2494 };
2495 
2496 // ----------------------------------------------------------------------------
2497 
2509 class PCL_CLASS XMLDocTypeDeclaration : public XMLComponent
2510 {
2511 public:
2512 
2517  XMLDocTypeDeclaration( const String& name = String(), const String& definition = String() )
2518  : m_name( name )
2519  , m_definition( definition )
2520  {
2521  }
2522 
2527 
2531  const String& Name() const
2532  {
2533  return m_name;
2534  }
2535 
2539  const String& Definition() const
2540  {
2541  return m_definition;
2542  }
2543 
2549  bool IsDefined() const
2550  {
2551  return !m_name.IsEmpty();
2552  }
2553 
2561  void Serialize( IsoString& text ) const;
2562 
2563 private:
2564 
2565  String m_name;
2566  String m_definition;
2567 };
2568 
2569 // ----------------------------------------------------------------------------
2570 
2599 {
2604  {
2605  }
2606 
2611  virtual bool operator()( const XMLElement* parent, const String& name ) const = 0;
2612 
2623  virtual bool operator()( const XMLElement* parent, const String& name, const XMLAttributeList& attributes ) const
2624  {
2625  return true;
2626  }
2627 };
2628 
2629 // ----------------------------------------------------------------------------
2630 
2644 namespace XMLParserOption
2645 {
2646  enum mask_type
2647  {
2648  IgnoreComments = 0x00000001,
2649  IgnoreUnknownElements = 0x00000002,
2650  IgnoreStrayCharacters = 0x00000004,
2651  NormalizeTextSpaces = 0x00000008
2652  };
2653 }
2654 
2660 using XMLParserOptions = Flags<XMLParserOption::mask_type>;
2661 
2662 // ----------------------------------------------------------------------------
2663 
2744 class PCL_CLASS XMLDocument
2745 {
2746 public:
2747 
2751  using iterator = XMLNodeList::iterator;
2752 
2756  using const_iterator = XMLNodeList::const_iterator;
2757 
2762  using parser_option = XMLParserOption::mask_type;
2763 
2774  XMLDocument() = default;
2775 
2780  virtual ~XMLDocument()
2781  {
2782  m_nodes.Destroy();
2783  m_root = nullptr;
2784  RemoveElementFilter();
2785  }
2786 
2791  XMLDocument( const XMLDocument& ) = delete;
2792 
2797  XMLDocument& operator =( const XMLDocument& ) = delete;
2798 
2803  const XMLDeclaration& XML() const
2804  {
2805  return m_xml;
2806  }
2807 
2811  void SetXML( const XMLDeclaration& xml )
2812  {
2813  m_xml = xml;
2814  }
2815 
2820  void SetXML( const String& version = "1.0", const String& encoding = "UTF-8", bool standalone = false )
2821  {
2822  SetXML( XMLDeclaration( version, encoding, standalone ) );
2823  }
2824 
2830  {
2831  return m_docType;
2832  }
2833 
2838  void SetDocType( const XMLDocTypeDeclaration& docType )
2839  {
2840  m_docType = docType;
2841  }
2842 
2850  const XMLElement* RootElement() const
2851  {
2852  return m_root;
2853  }
2854 
2869  {
2870  XMLElement* root = m_root;
2871  m_nodes.RemovePointer( m_root );
2872  Clear();
2873  return root;
2874  }
2875 
2880  int NodeCount() const
2881  {
2882  return int( m_nodes.Length() );
2883  }
2884 
2889  bool IsEmpty() const
2890  {
2891  return m_nodes.IsEmpty();
2892  }
2893 
2899  const XMLNode& operator []( int i ) const
2900  {
2901  return m_nodes[i];
2902  }
2903 
2909  {
2910  return m_nodes.Begin();
2911  }
2912 
2918  {
2919  return m_nodes.End();
2920  }
2921 
2922 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
2927  {
2928  return Begin();
2929  }
2930 
2935  {
2936  return End();
2937  }
2938 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
2939 
2954  void AddNode( XMLNode* node );
2955 
2962  {
2963  AddNode( node );
2964  return *this;
2965  }
2966 
2980  void SetRootElement( XMLElement* element );
2981 
2993  void Clear();
2994 
3006  {
3007  XMLElement dum;
3008  m_nodes.Destroy( dum,
3009  [&]( const XMLNode& node, const XMLNode& )
3010  {
3011  if ( node.IsElement() )
3012  {
3013  const XMLElement& element = static_cast<const XMLElement&>( node );
3014  if ( !filter( nullptr, element.Name() ) ||
3015  !filter( nullptr, element.Name(), element.Attributes() ) )
3016  return true;
3017  }
3018  return false;
3019  } );
3020  }
3021 
3027  void RemoveElementsByName( const String& name, bool caseSensitive = true )
3028  {
3029  XMLElement dum;
3030  m_nodes.Destroy( dum,
3031  [&]( const XMLNode& node, const XMLNode& )
3032  {
3033  if ( node.IsElement() )
3034  {
3035  const XMLElement& element = static_cast<const XMLElement&>( node );
3036  if ( (caseSensitive ? element.Name().Compare( name ) : element.Name().CompareIC( name )) == 0 )
3037  return true;
3038  }
3039  return false;
3040  } );
3041  }
3042 
3053  {
3054  delete m_filter, m_filter = filter;
3055  }
3056 
3063  {
3064  SetElementFilter( nullptr );
3065  }
3066 
3072  void SetParserOption( parser_option option, bool on = true )
3073  {
3074  m_parserOptions.SetFlag( option, on );
3075  }
3076 
3083  {
3084  m_parserOptions = options;
3085  }
3086 
3092  {
3093  m_parserOptions.Clear();
3094  }
3095 
3108  void Parse( const String& text );
3109 
3129  bool IsAutoFormatting() const
3130  {
3131  return m_autoFormatting;
3132  }
3133 
3138  void EnableAutoFormatting( bool enable = true )
3139  {
3140  m_autoFormatting = enable;
3141  }
3142 
3147  void DisableAutoFormatting( bool disable = true )
3148  {
3149  EnableAutoFormatting( !disable );
3150  }
3151 
3161  int IndentSize() const
3162  {
3163  return m_indentSize;
3164  }
3165 
3189  void SetIndentSize( int indentSize )
3190  {
3191  m_indentSize = Range( indentSize, 0, 8 );
3192  }
3193 
3202  bool IsIndentTabs() const
3203  {
3204  return m_indentTabs;
3205  }
3206 
3211  void EnableIndentTabs( bool enable = true )
3212  {
3213  m_indentTabs = enable;
3214  }
3215 
3220  void DisableIndentTabs( bool disable = true )
3221  {
3222  EnableIndentTabs( !disable );
3223  }
3224 
3237  {
3238  return Serialize( false/*isHTML*/ );
3239  }
3240 
3255  {
3256  return Serialize( true/*isHTML*/ );
3257  }
3258 
3268  void SerializeToFile( const String& path ) const;
3269 
3280  void SerializeToFileAsHTML( const String& path ) const;
3281 
3282 private:
3283 
3284  XMLDeclaration m_xml;
3285  XMLDocTypeDeclaration m_docType;
3286  XMLNodeList m_nodes;
3287  XMLElement* m_root = nullptr;
3288  XMLElementFilter* m_filter = nullptr;
3289  XMLParserOptions m_parserOptions;
3290  XMLNodeLocation m_location;
3291  bool m_autoFormatting = false;
3292  bool m_indentTabs = false;
3293  int m_indentSize = 3;
3294 
3295  IsoString Serialize( bool isHTML ) const;
3296 };
3297 
3298 // ----------------------------------------------------------------------------
3299 
3300 } // pcl
3301 
3302 #endif // __PCL_XML_h
3303 
3304 // ----------------------------------------------------------------------------
3305 // EOF pcl/XML.h - Released 2024-12-28T16:53:48Z
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:830
iterator Begin()
Definition: String.h:988
iterator End()
Definition: String.h:1018
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5443
Unicode (UTF-16) string.
Definition: String.h:8146
string_base::const_iterator const_iterator
Definition: String.h:8217
Dynamic list of XML element attributes.
Definition: XML.h:877
void SetAttribute(const String &name, const String &value)
Definition: XML.h:1019
const_iterator begin() const
Definition: XML.h:970
bool IsEmpty() const
Definition: XML.h:933
XMLAttributeList(const String &text)
Definition: XML.h:907
XMLAttributeList()=default
const_iterator end() const
Definition: XML.h:978
const_iterator End() const
Definition: XML.h:961
void SetAttribute(const XMLAttribute &attribute)
Definition: XML.h:1036
bool HasAttribute(const String &name) const
Definition: XML.h:988
String AttributeValue(const String &name) const
Definition: XML.h:998
void RemoveAttribute(const String &name)
Definition: XML.h:1096
void Parse(const String &text)
XMLAttributeList(const XMLAttributeList &)=default
void SetAttributes(const XMLAttributeList &list)
Definition: XML.h:1074
void Serialize(IsoString &text) const
const_iterator Begin() const
Definition: XML.h:952
int Length() const
Definition: XML.h:925
XML element attribute
Definition: XML.h:763
void SetValue(const String &text)
Definition: XML.h:815
XMLAttribute(const XMLAttribute &)=default
const String & Value() const
Definition: XML.h:807
XMLAttribute()=default
XMLAttribute(const String &name, const String &value=String())
Definition: XML.h:785
String EncodedValue() const
Definition: XML.h:825
const String & Name() const
Definition: XML.h:799
XML CDATA section
Definition: XML.h:2134
XMLNode * Clone() const override
Definition: XML.h:2172
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & CData() const
Definition: XML.h:2164
XMLCDATA(const XMLCDATA &)=default
XML comment section
Definition: XML.h:2281
XMLComment(const String &comment)
Definition: XML.h:2292
const String & Comment() const
Definition: XML.h:2311
XMLNode * Clone() const override
Definition: XML.h:2319
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:2425
bool IsDefined() const
Definition: XML.h:2473
bool IsStandaloneDocument() const
Definition: XML.h:2463
XMLDeclaration(const String &version=String(), const String &encoding=String(), bool standalone=false)
Definition: XML.h:2432
void Serialize(IsoString &text) const
const String & DocumentEncoding() const
Definition: XML.h:2455
const String & Version() const
Definition: XML.h:2447
XMLDeclaration(const XMLDeclaration &)=default
XML DOCTYPE declaration
Definition: XML.h:2510
XMLDocTypeDeclaration(const String &name=String(), const String &definition=String())
Definition: XML.h:2517
const String & Definition() const
Definition: XML.h:2539
bool IsDefined() const
Definition: XML.h:2549
const String & Name() const
Definition: XML.h:2531
XMLDocTypeDeclaration(const XMLDocTypeDeclaration &)=default
void Serialize(IsoString &text) const
XML document parsing and generation
Definition: XML.h:2745
bool IsEmpty() const
Definition: XML.h:2889
void SerializeToFileAsHTML(const String &path) const
IsoString SerializeAsHTML() const
Definition: XML.h:3254
XMLNodeList::const_iterator const_iterator
Definition: XML.h:2756
const XMLDeclaration & XML() const
Definition: XML.h:2803
bool IsIndentTabs() const
Definition: XML.h:3202
XMLElement * ReleaseRootElement()
Definition: XML.h:2868
void SetParserOption(parser_option option, bool on=true)
Definition: XML.h:3072
const XMLDocTypeDeclaration & DocType() const
Definition: XML.h:2829
int IndentSize() const
Definition: XML.h:3161
XMLDocument(const XMLDocument &)=delete
void SetRootElement(XMLElement *element)
virtual ~XMLDocument()
Definition: XML.h:2780
XMLNodeList::iterator iterator
Definition: XML.h:2751
void RemoveElementsByName(const String &name, bool caseSensitive=true)
Definition: XML.h:3027
const_iterator Begin() const
Definition: XML.h:2908
const_iterator begin() const
Definition: XML.h:2926
void EnableIndentTabs(bool enable=true)
Definition: XML.h:3211
void DisableIndentTabs(bool disable=true)
Definition: XML.h:3220
void EnableAutoFormatting(bool enable=true)
Definition: XML.h:3138
void SerializeToFile(const String &path) const
const_iterator End() const
Definition: XML.h:2917
const XMLElement * RootElement() const
Definition: XML.h:2850
bool IsAutoFormatting() const
Definition: XML.h:3129
void SetXML(const XMLDeclaration &xml)
Definition: XML.h:2811
void RemoveElementsByFilter(const XMLElementFilter &filter)
Definition: XML.h:3005
void SetElementFilter(XMLElementFilter *filter)
Definition: XML.h:3052
void SetXML(const String &version="1.0", const String &encoding="UTF-8", bool standalone=false)
Definition: XML.h:2820
void DisableAutoFormatting(bool disable=true)
Definition: XML.h:3147
XMLDocument()=default
void SetDocType(const XMLDocTypeDeclaration &docType)
Definition: XML.h:2838
IsoString Serialize() const
Definition: XML.h:3236
void ClearParserOptions()
Definition: XML.h:3091
void SetParserOptions(XMLParserOptions options)
Definition: XML.h:3082
void Parse(const String &text)
int NodeCount() const
Definition: XML.h:2880
const_iterator end() const
Definition: XML.h:2934
void RemoveElementFilter()
Definition: XML.h:3062
void AddNode(XMLNode *node)
void SetIndentSize(int indentSize)
Definition: XML.h:3189
XML element
Definition: XML.h:1177
bool HasChildNodeThat(UP u, bool recursive=false) const
Definition: XML.h:1824
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
iterator begin()
Definition: XML.h:1597
void SortAttributes()
Definition: XML.h:1422
bool HasAttribute(const String &name) const
Definition: XML.h:1308
int ChildCount() const
Definition: XML.h:1475
const_iterator ConstBegin() const
Definition: XML.h:1579
XMLElement(const String &name, const XMLAttributeList &attributes=XMLAttributeList())
Definition: XML.h:1208
void SerializeAsHTML(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
String Text() const
const_iterator End() const
Definition: XML.h:1532
void SetAttribute(const XMLAttribute &attribute)
Definition: XML.h:1350
bool IsRootElement() const
Definition: XML.h:1275
~XMLElement() override
Definition: XML.h:1260
String AttributeValue(const String &name) const
Definition: XML.h:1318
iterator end()
Definition: XML.h:1605
bool HasElements() const
Definition: XML.h:1616
void SetAttribute(const String &name, const String &value)
Definition: XML.h:1338
bool HasAttributes() const
Definition: XML.h:1299
XMLNodeList::iterator iterator
Definition: XML.h:1183
bool HasChildElementWithName(const String &name, bool recursive=false) const
Definition: XML.h:1734
child_element_list ChildElementsByName(const String &name, bool recursive=false) const
Definition: XML.h:1719
XMLElement(const XMLElement &x)
Definition: XML.h:1231
void SetAttributes(const XMLAttributeList &list)
Definition: XML.h:1383
const XMLNode & Last() const
Definition: XML.h:1514
const_iterator end() const
Definition: XML.h:1549
XMLNode * Clone() const override
Definition: XML.h:1932
XMLNodeList::const_iterator const_iterator
Definition: XML.h:1188
bool HasComments() const
Definition: XML.h:1650
void AddChildNode(XMLNode *node)
Definition: XML.h:1844
iterator End()
Definition: XML.h:1570
XMLNodeList ChildNodesThat(UP u, bool recursive=false) const
Definition: XML.h:1808
void RemoveAttribute(const String &name)
Definition: XML.h:1405
void ParseAttributes(const String &text)
Definition: XML.h:1450
iterator Begin()
Definition: XML.h:1561
XMLNodeList ChildNodesByType(XMLNodeTypes types, bool recursive=false) const
Definition: XML.h:1773
void DestroyChildNodes()
Definition: XML.h:1906
void SerializeAttributes(IsoString &text) const
Definition: XML.h:1467
XMLNodeList ReleaseChildNodes()
Definition: XML.h:1921
bool HasCDATA() const
Definition: XML.h:1632
void ClearAttributes()
Definition: XML.h:1413
const_iterator begin() const
Definition: XML.h:1541
const_iterator Begin() const
Definition: XML.h:1523
XMLElement(XMLElement &parent, const String &name, const XMLAttributeList &attributes=XMLAttributeList())
Definition: XML.h:1220
void SortAttributes(BP p)
Definition: XML.h:1434
bool HasProcessingInstructions() const
Definition: XML.h:1641
const_iterator ConstEnd() const
Definition: XML.h:1588
bool IsEmpty() const
Definition: XML.h:1484
const XMLNode & First() const
Definition: XML.h:1504
void AddChildNodes(XMLNodeList &nodes)
Definition: XML.h:1871
ReferenceArray< XMLElement > child_element_list
Definition: XML.h:1194
XMLAttributeList Attributes() const
Definition: XML.h:1291
bool HasText() const
Definition: XML.h:1624
child_element_list ChildElements(bool recursive=false) const
Definition: XML.h:1686
const String & Name() const
Definition: XML.h:1283
Abstract base class of all XML document node classes.
Definition: XML.h:507
virtual XMLNode * Clone() const =0
bool IsText() const
Definition: XML.h:585
bool IsElement() const
Definition: XML.h:576
~XMLNode() override
Definition: XML.h:552
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:651
virtual void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const =0
const XMLNodeLocation & Location() const
Definition: XML.h:602
virtual bool NLAfter(const XMLNode &previous) const
bool IsComment() const
Definition: XML.h:594
XMLNode(node_type type)
Definition: XML.h:521
bool IsChildNode() const
Definition: XML.h:559
node_type NodeType() const
Definition: XML.h:567
XML parsing error with automatic text location information generation
Definition: XML.h:698
XMLParseError(const XMLNode &node, const String &whileDoing, const String &whatHappened)
Definition: XML.h:717
XMLParseError(const XMLNodeLocation &where, const String &whileDoing, const String &whatHappened)
Definition: XML.h:738
XMLParseError(const XMLParseError &)=default
A collection of XML document parsing options.
XML processing instructions
Definition: XML.h:2203
XMLProcessingInstructions(const String &target, const String &instructions)
Definition: XML.h:2214
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & Target() const
Definition: XML.h:2234
XMLNode * Clone() const override
Definition: XML.h:2250
const String & Instructions() const
Definition: XML.h:2242
XMLProcessingInstructions & operator=(const XMLProcessingInstructions &)=default
XMLProcessingInstructions(const XMLProcessingInstructions &)=default
XML text block
Definition: XML.h:1991
XMLText(const String &text, bool preserveSpaces=true, bool verbatim=false)
Definition: XML.h:2019
XMLText(const XMLText &)=default
bool IsPreserveSpaces() const
Definition: XML.h:2050
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
XMLNode * Clone() const override
Definition: XML.h:2086
bool NLAfter(const XMLNode &previous) const override
Definition: XML.h:2109
const String & Text() const
Definition: XML.h:2041
String SpaceTransformedText(bool collapse, bool trim) const
Definition: XML.h:2073
String EncodedText() const
Definition: XML.h:2060
Unsupported or invalid XML element.
Definition: XML.h:2351
XMLUnknownElement(const XMLUnknownElement &)=default
XMLUnknownElement(const String &name, const String &parameters=String())
Definition: XML.h:2358
const String & Parameters() const
Definition: XML.h:2386
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
XMLNode * Clone() const override
Definition: XML.h:2394
const String & Name() const
Definition: XML.h:2378
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:2313
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2285
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2296
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:2599
virtual ~XMLElementFilter()
Definition: XML.h:2603
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:2623
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