74 class PCL_CLASS XMLDocument;
75 class PCL_CLASS XMLElement;
116 template <
typename T>
119 return c == 0x20 || c == 9;
126 template <
typename T>
129 return c == 0x0A || c == 0x0D;
137 template <
typename T>
140 return IsWhiteSpaceChar( c ) || IsLineBreakChar( c );
148 template <
typename T>
151 return c >= T(
'a' ) && c <= T(
'z' )
152 || c >= T(
'A' ) && c <= T(
'Z' )
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
174 template <
typename T>
177 return IsNameStartChar( c )
178 || c >= T(
'0' ) && c <= T(
'9' )
182 || c >= 0x0300 && c <= 0x036F
183 || c >= 0x203F && c <= 0x2040;
191 template <
typename T>
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;
210 if ( IsNameStartChar( *name ) )
213 if ( ++i == name.
End() )
215 if ( !IsNameChar( *i ) )
280 return EncodedText(
String( i, j ), apos );
318 return ReferenceValue( reference.
Begin(), reference.
End() );
371 return m_parent ==
nullptr;
401 namespace XMLNodeType
405 Undefined = 0x00000000,
406 ChildNode = 0x80000000,
407 Unknown = 0x10000000,
408 Element = 0x00000001,
411 ProcessingInstructions = 0x00000008,
514 using node_type = XMLNodeType::mask_type;
534 : m_type( x.NodeType() )
535 , m_location( x.m_location )
551 return m_type.IsFlagSet( XMLNodeType::ChildNode );
568 return NodeType() == XMLNodeType::Element;
577 return NodeType() == XMLNodeType::Text;
586 return NodeType() == XMLNodeType::Comment;
622 virtual void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const = 0;
638 Serialize( text, autoFormat, indentChar, indentSize, level );
703 :
Error( whileDoing + node.Location().ToString() +
": " + whatHappened )
724 :
Error( whileDoing + where.ToString() +
": " + whatHappened )
824 return m_name == x.m_name;
836 return m_name < x.m_name;
912 return int( m_list.Length() );
920 return m_list.IsEmpty();
939 return m_list.Begin();
951 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
975 return m_list.Contains( name );
986 return (a != m_list.End()) ? a->Value() :
String();
1008 iterator a = m_list.Search( name );
1009 if ( a == m_list.End() )
1012 a->SetValue( value );
1025 iterator a = m_list.Search( attribute );
1026 if ( a == m_list.End() )
1027 m_list.Add( attribute );
1040 SetAttribute( attribute );
1061 for (
auto a : list )
1072 SetAttributes( list );
1083 iterator a = m_list.Search( name );
1084 if ( a != m_list.End() )
1185 :
XMLNode( XMLNodeType::Element )
1194 :
XMLNode( XMLNodeType::Element )
1196 , m_attributes( attributes )
1206 :
XMLNode( XMLNodeType::Element )
1208 , m_attributes( attributes )
1231 DestroyChildNodes();
1246 return ParentElement() ==
nullptr;
1262 return m_attributes;
1270 return !m_attributes.IsEmpty();
1279 return m_attributes.HasAttribute( name );
1289 return m_attributes.AttributeValue( name );
1311 m_attributes.SetAttribute( a );
1323 m_attributes.SetAttribute( a );
1333 SetAttribute( attribute );
1354 for (
auto a : list )
1365 SetAttributes( list );
1376 m_attributes.RemoveAttribute( name );
1384 m_attributes.Clear();
1393 m_attributes.Sort();
1405 m_attributes.Sort( p );
1423 SetAttributes( list );
1438 m_attributes.Serialize( text );
1446 return int( m_childNodes.Length() );
1455 return m_childNodes.IsEmpty();
1465 return m_childNodes[i];
1475 return m_childNodes.First();
1485 return m_childNodes.Last();
1494 return m_childNodes.Begin();
1503 return m_childNodes.End();
1506 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1524 #ifndef __PCL_NO_MUTABLE_XML_ELEMENT_ITERATORS
1532 return m_childNodes.Begin();
1541 return m_childNodes.End();
1550 return m_childNodes.ConstBegin();
1559 return m_childNodes.ConstEnd();
1562 # ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1587 return m_childTypes.IsFlagSet( XMLNodeType::Element );
1595 return m_childTypes.IsFlagSet( XMLNodeType::Text );
1603 return m_childTypes.IsFlagSet( XMLNodeType::CDATA );
1612 return m_childTypes.IsFlagSet( XMLNodeType::ProcessingInstructions );
1621 return m_childTypes.IsFlagSet( XMLNodeType::Comment );
1638 for (
const XMLNode& node : m_childNodes )
1639 if ( node.IsElement() )
1644 element.GetChildElements( list, recursive );
1658 GetChildElements( list, recursive );
1665 void GetChildElementsByName( child_element_list& list,
const String& name,
bool recursive )
const
1667 for (
const XMLNode& node : m_childNodes )
1668 if ( node.IsElement() )
1671 if ( element.
Name() == name )
1675 element.GetChildElementsByName( list, name, recursive );
1691 GetChildElementsByName( list, name, recursive );
1705 for (
const XMLNode& node : m_childNodes )
1706 if ( node.IsElement() )
1709 if ( element.
Name() == name )
1723 for (
const XMLNode& node : m_childNodes )
1724 if ( types.
IsFlagSet( node.NodeType() ) )
1728 if ( node.IsElement() )
1729 static_cast<const XMLElement&
>( node ).GetChildNodesByType( list, types, recursive );
1745 GetChildNodesByType( list, types, recursive );
1753 void GetChildNodesThat(
XMLNodeList& list, UP u,
bool recursive )
const
1755 for (
const XMLNode& node : m_childNodes )
1760 if ( node.IsElement() )
1761 static_cast<const XMLElement&
>( node ).GetChildNodesThat( list, u, recursive );
1780 GetChildNodesThat( list, u, recursive );
1795 for (
const XMLNode& node : m_childNodes )
1800 if ( node.IsElement() )
1801 if (
static_cast<const XMLElement&
>( node ).HasChildNodeThat( u, recursive ) )
1815 m_childNodes << node;
1816 node->m_parent =
this;
1817 node->m_type.
SetFlag( XMLNodeType::ChildNode );
1818 m_childTypes.SetFlag( node->
NodeType() );
1829 AddChildNode( node );
1843 AddChildNode( &node );
1854 AddChildNodes( nodes );
1867 node->m_location = location;
1868 AddChildNode( node );
1877 m_childNodes.Destroy();
1878 m_childTypes = XMLNodeType::Undefined;
1893 m_childNodes.
Clear();
1894 m_childTypes = XMLNodeType::Undefined;
1905 void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const override;
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 )
2008 return m_preserveSpaces;
2046 void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const override;
2059 return !m_preserveSpaces;
2065 bool m_preserveSpaces =
true;
2066 bool m_verbatim =
false;
2093 :
XMLNode( XMLNodeType::CDATA )
2117 void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const override;
2150 :
XMLNode( XMLNodeType::ProcessingInstructions )
2151 , m_target( target )
2152 , m_instructions( instructions )
2174 return m_instructions;
2182 void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const override;
2215 :
XMLNode( XMLNodeType::Comment )
2216 , m_comment( comment )
2238 void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const override;
2268 :
XMLNode( XMLNodeType::Unknown )
2270 , m_parameters( parameters )
2292 return m_parameters;
2300 void Serialize(
IsoString& text,
bool autoFormat,
char indentChar,
unsigned indentSize,
unsigned level )
const override;
2329 : m_version( version )
2330 , m_encoding( encoding )
2331 , m_standalone( standalone )
2361 return m_standalone;
2371 return !m_version.IsEmpty();
2389 bool m_standalone =
false;
2415 , m_definition( definition )
2437 return m_definition;
2447 return !m_name.IsEmpty();
2540 namespace XMLParserOption
2544 IgnoreComments = 0x00000001,
2545 IgnoreUnknownElements = 0x00000002,
2546 IgnoreStrayCharacters = 0x00000004,
2547 NormalizeTextSpaces = 0x00000008
2658 using parser_option = XMLParserOption::mask_type;
2680 RemoveElementFilter();
2736 m_docType = docType;
2767 m_nodes.RemovePointer( m_root );
2778 return int( m_nodes.Length() );
2787 return m_nodes.IsEmpty();
2806 return m_nodes.Begin();
2815 return m_nodes.End();
2818 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
2904 m_nodes.Destroy( dum,
2909 const XMLElement& element = static_cast<const XMLElement&>( node );
2910 if ( !filter( nullptr, element.Name() ) ||
2911 !filter( nullptr, element.Name(), element.Attributes() ) )
2926 m_nodes.Destroy( dum,
2931 const XMLElement& element = static_cast<const XMLElement&>( node );
2932 if ( (caseSensitive ? element.Name().Compare( name ) : element.Name().CompareIC( name )) == 0 )
2950 delete m_filter, m_filter = filter;
2960 SetElementFilter(
nullptr );
2970 m_parserOptions.SetFlag( option, on );
2980 m_parserOptions = options;
2989 m_parserOptions.Clear();
3027 return m_autoFormatting;
3036 m_autoFormatting = enable;
3045 EnableAutoFormatting( !disable );
3059 return m_indentSize;
3087 m_indentSize =
Range( indentSize, 0, 8 );
3100 return m_indentTabs;
3109 m_indentTabs = enable;
3118 EnableIndentTabs( !disable );
3134 return Serialize(
false );
3152 return Serialize(
true );
3187 bool m_autoFormatting =
false;
3188 bool m_indentTabs =
false;
3189 int m_indentSize = 3;
3191 IsoString Serialize(
bool isHTML )
const;
A simple exception with an associated error message.
constexpr bool IsFlagSet(enum_type e) const
void SetFlag(enum_type e, bool on=true)
typename FlagType< std::is_unsigned< enum_type >::value >::type flag_type
bool IsEmpty() const noexcept
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
string_base::const_iterator const_iterator
Dynamic list of XML element attributes.
void SetAttribute(const String &name, const String &value)
const_iterator begin() const
XMLAttributeList(const String &text)
XMLAttributeList()=default
const_iterator end() const
const_iterator End() const
void SetAttribute(const XMLAttribute &attribute)
bool HasAttribute(const String &name) const
String AttributeValue(const String &name) const
void RemoveAttribute(const String &name)
void Parse(const String &text)
XMLAttributeList(const XMLAttributeList &)=default
void SetAttributes(const XMLAttributeList &list)
void Serialize(IsoString &text) const
const_iterator Begin() const
void SetValue(const String &text)
XMLAttribute(const XMLAttribute &)=default
const String & Value() const
XMLAttribute(const String &name, const String &value=String())
String EncodedValue() const
const String & Name() const
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & CData() const
XMLCDATA(const XMLCDATA &)=default
Root base class of all XML document components.
XMLComponent(const XMLComponent &)=default
XMLElement * ParentElement() const
bool IsStandaloneDocument() const
XMLDeclaration(const String &version=String(), const String &encoding=String(), bool standalone=false)
void Serialize(IsoString &text) const
const String & DocumentEncoding() const
const String & Version() const
XMLDeclaration(const XMLDeclaration &)=default
XMLDocTypeDeclaration(const String &name=String(), const String &definition=String())
const String & Definition() const
const String & Name() const
XMLDocTypeDeclaration(const XMLDocTypeDeclaration &)=default
void Serialize(IsoString &text) const
XML document parsing and generation
void SerializeToFileAsHTML(const String &path) const
IsoString SerializeAsHTML() const
XMLNodeList::const_iterator const_iterator
const XMLDeclaration & XML() const
bool IsIndentTabs() const
XMLElement * ReleaseRootElement()
void SetParserOption(parser_option option, bool on=true)
const XMLDocTypeDeclaration & DocType() const
XMLDocument(const XMLDocument &)=delete
void SetRootElement(XMLElement *element)
XMLNodeList::iterator iterator
void RemoveElementsByName(const String &name, bool caseSensitive=true)
const_iterator Begin() const
const_iterator begin() const
void EnableIndentTabs(bool enable=true)
void DisableIndentTabs(bool disable=true)
void EnableAutoFormatting(bool enable=true)
void SerializeToFile(const String &path) const
const_iterator End() const
const XMLElement * RootElement() const
bool IsAutoFormatting() const
void SetXML(const XMLDeclaration &xml)
void RemoveElementsByFilter(const XMLElementFilter &filter)
void SetElementFilter(XMLElementFilter *filter)
void SetXML(const String &version="1.0", const String &encoding="UTF-8", bool standalone=false)
void DisableAutoFormatting(bool disable=true)
void SetDocType(const XMLDocTypeDeclaration &docType)
IsoString Serialize() const
void ClearParserOptions()
void SetParserOptions(XMLParserOptions options)
void Parse(const String &text)
const_iterator end() const
void RemoveElementFilter()
void AddNode(XMLNode *node)
void SetIndentSize(int indentSize)
bool HasChildNodeThat(UP u, bool recursive=false) const
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
bool HasAttribute(const String &name) const
const_iterator ConstBegin() const
XMLElement(const String &name, const XMLAttributeList &attributes=XMLAttributeList())
void SerializeAsHTML(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const_iterator End() const
void SetAttribute(const XMLAttribute &attribute)
bool IsRootElement() const
String AttributeValue(const String &name) const
void SetAttribute(const String &name, const String &value)
bool HasAttributes() const
XMLNodeList::iterator iterator
bool HasChildElementWithName(const String &name, bool recursive=false) const
child_element_list ChildElementsByName(const String &name, bool recursive=false) const
void SetAttributes(const XMLAttributeList &list)
XMLElement(const XMLElement &)=delete
const XMLNode & Last() const
const_iterator end() const
XMLNodeList::const_iterator const_iterator
void AddChildNode(XMLNode *node)
XMLNodeList ChildNodesThat(UP u, bool recursive=false) const
void RemoveAttribute(const String &name)
void ParseAttributes(const String &text)
XMLNodeList ChildNodesByType(XMLNodeTypes types, bool recursive=false) const
void SerializeAttributes(IsoString &text) const
XMLNodeList ReleaseChildNodes()
const_iterator begin() const
const_iterator Begin() const
XMLElement(XMLElement &parent, const String &name, const XMLAttributeList &attributes=XMLAttributeList())
void SortAttributes(BP p)
bool HasProcessingInstructions() const
const_iterator ConstEnd() const
const XMLNode & First() const
void AddChildNodes(XMLNodeList &nodes)
ReferenceArray< XMLElement > child_element_list
XMLAttributeList Attributes() const
child_element_list ChildElements(bool recursive=false) const
const String & Name() const
Abstract base class of all XML document node classes.
XMLNode(const XMLNode &x)
virtual void SerializeAsHTML(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const
virtual void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const =0
const XMLNodeLocation & Location() const
virtual bool NLAfter(const XMLNode &previous) const
node_type NodeType() const
XML parsing error with automatic text location information generation
XMLParseError(const XMLNode &node, const String &whileDoing, const String &whatHappened)
XMLParseError(const XMLNodeLocation &where, const String &whileDoing, const String &whatHappened)
XMLParseError(const XMLParseError &)=default
A collection of XML document parsing options.
XML processing instructions
XMLProcessingInstructions(const String &target, const String &instructions)
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & Target() const
const String & Instructions() const
XMLProcessingInstructions(const XMLProcessingInstructions &)=default
XMLText(const String &text, bool preserveSpaces=true, bool verbatim=false)
XMLText(const XMLText &)=default
bool IsPreserveSpaces() const
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
bool NLAfter(const XMLNode &previous) const override
const String & Text() const
String SpaceTransformedText(bool collapse, bool trim) const
String EncodedText() const
Unsupported or invalid XML element.
XMLUnknownElement(const XMLUnknownElement &)=default
XMLUnknownElement(const String &name, const String ¶meters=String())
const String & Parameters() const
void Serialize(IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
const String & Name() const
Utility functions and data for XML document parsing and generation.
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)
static String EncodedText(const String &text, bool apos=true)
static bool IsValidName(const String &name)
static String CollapsedSpaces(const String &text)
static bool IsWhiteSpaceChar(T c)
static String ReferenceValue(const String &reference)
static String DecodedText(const String &text)
static bool IsSpaceChar(T c)
static bool IsNameStartChar(T c)
static String CollapsedSpaces(String::const_iterator i, String::const_iterator j)
static bool IsRestrictedChar(T c)
static bool IsNameChar(T c)
static bool IsLineBreakChar(T c)
static String ReferenceValue(String::const_iterator i, String::const_iterator j)
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
String AsString(mask_type type)
A functional class for filtering XML elements.
virtual ~XMLElementFilter()
virtual bool operator()(const XMLElement *parent, const String &name) const =0
virtual bool operator()(const XMLElement *parent, const String &name, const XMLAttributeList &attributes) const
Source code location of a parsed XML document node.
XMLNodeLocation(const XMLNodeLocation &)=default
XMLNodeLocation(int line_, int column_)
XMLNodeLocation()=default