Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
* Set node name to \a rhs (for PI/element nodes). \see name
*
* \param rhs - new node name
* \return success flag (call fails if node is of the wrong type or there is not enough memory)
*/
bool set_name(const char_t* rhs);
/**
* Set node value to \a rhs (for PI/PCDATA/CDATA/comment nodes). \see value
*
* \param rhs - new node value
* \return success flag (call fails if node is of the wrong type or there is not enough memory)
*/
bool set_value(const char_t* rhs);
/**
* Add attribute with specified name (for element nodes)
*
* \param name - attribute name
* \return added attribute, or empty attribute if there was an error (wrong node type)
*/
xml_attribute append_attribute(const char_t* name);
/**
* Insert attribute with specified name after \a attr (for element nodes)
*
* \param name - attribute name
* \param attr - attribute to insert a new one after
* \return inserted attribute, or empty attribute if there was an error (wrong node type, or attr does not belong to node)
*/
xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
/**
* Insert attribute with specified name before \a attr (for element nodes)
*
* \param name - attribute name
* \param attr - attribute to insert a new one before
* \return inserted attribute, or empty attribute if there was an error (wrong node type, or attr does not belong to node)
*/
xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
/**
* Add a copy of the specified attribute (for element nodes)
*
* \param proto - attribute prototype which is to be copied
* \return inserted attribute, or empty attribute if there was an error (wrong node type)
*/
xml_attribute append_copy(const xml_attribute& proto);
/**
* Insert a copy of the specified attribute after \a attr (for element nodes)
*
* \param proto - attribute prototype which is to be copied
* \param attr - attribute to insert a new one after
* \return inserted attribute, or empty attribute if there was an error (wrong node type, or attr does not belong to node)
*/
xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
/**
* Insert a copy of the specified attribute before \a attr (for element nodes)
*
* \param proto - attribute prototype which is to be copied
* \param attr - attribute to insert a new one before
* \return inserted attribute, or empty attribute if there was an error (wrong node type, or attr does not belong to node)
*/
xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
/**
* Add child node with specified type (for element nodes)
*
* \param type - node type
* \return added node, or empty node if there was an error (wrong node type)
*/
xml_node append_child(xml_node_type type = node_element);
/**
* Insert child node with specified type after \a node (for element nodes)
*
* \param type - node type
* \param node - node to insert a new one after
* \return inserted node, or empty node if there was an error (wrong node type, or \a node is not a child of this node)
*/
xml_node insert_child_after(xml_node_type type, const xml_node& node);
/**
* Insert child node with specified type before \a node (for element nodes)
*
* \param type - node type
* \param node - node to insert a new one before
* \return inserted node, or empty node if there was an error (wrong node type, or \a node is not a child of this node)
*/
xml_node insert_child_before(xml_node_type type, const xml_node& node);
/**
* Add a copy of the specified node as a child (for element nodes)
*
* \param proto - node prototype which is to be copied
* \return inserted node, or empty node if there was an error (wrong node type)
*/
xml_node append_copy(const xml_node& proto);
/**
* Insert a copy of the specified node after \a node (for element nodes)
*
* \param proto - node prototype which is to be copied
* \param node - node to insert a new one after
* \return inserted node, or empty node if there was an error (wrong node type, or \a node is not a child of this node)
*/
xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
/**
* Insert a copy of the specified node before \a node (for element nodes)
*
* \param proto - node prototype which is to be copied
* \param node - node to insert a new one before
* \return inserted node, or empty node if there was an error (wrong node type, or \a node is not a child of this node)
*/
xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
/**
* Remove specified attribute
*
* \param a - attribute to be removed
* \return success flag
*/
bool remove_attribute(const xml_attribute& a);
/**
* Remove attribute with the specified name, if any
*
* \param name - attribute name
* \return success flag
*/
bool remove_attribute(const char_t* name);
/**
* Remove specified child
*
* \param n - child node to be removed
* \return success flag
*/
bool remove_child(const xml_node& n);
/**
* Remove child with the specified name, if any
*
* \param name - child name
* \return success flag
*/
bool remove_child(const char_t* name);
public:
/**
* Get first attribute
*
* \return first attribute, if any; empty attribute otherwise
*/
xml_attribute first_attribute() const;
/**
* Get last attribute
*
* \return last attribute, if any; empty attribute otherwise
*/
xml_attribute last_attribute() const;
/**
* Get all elements from subtree with given name
*
* \param name - node name
* \param it - output iterator (for example, std::back_insert_iterator (result of std::back_inserter))
*
* \deprecated This function is deprecated
*/
template <typename OutputIterator> PUGIXML_DEPRECATED void all_elements_by_name(const char_t* name, OutputIterator it) const
{
all_elements_by_name_helper(name, it);
}
/**
* Get all elements from subtree with name that matches given pattern
*
* \param name - node name pattern
* \param it - output iterator (for example, std::back_insert_iterator (result of std::back_inserter))
*
* \deprecated This function is deprecated
*/
template <typename OutputIterator> PUGIXML_DEPRECATED void all_elements_by_name_w(const char_t* name, OutputIterator it) const
{
all_elements_by_name_w_helper(name, it);
}
/**
* Get first child
*
* \return first child, if any; empty node otherwise
*/
xml_node first_child() const;
/**
* Get last child
*
* \return last child, if any; empty node otherwise
*/
xml_node last_child() const;
/**
* Find attribute using predicate
*
* \param pred - predicate, that takes xml_attribute and returns bool
* \return first attribute for which predicate returned true, or empty attribute
*/
template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
{
if (!_root) return xml_attribute();
for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
if (pred(attrib))
return attrib;
return xml_attribute();
}
/**
* Find child node using predicate
*
* \param pred - predicate, that takes xml_node and returns bool
* \return first child node for which predicate returned true, or empty node
*/
template <typename Predicate> xml_node find_child(Predicate pred) const
{
if (!_root) return xml_node();
for (xml_node node = first_child(); node; node = node.next_sibling())
if (pred(node))
return node;
return xml_node();
}
/**
* Find node from subtree using predicate
*
* \param pred - predicate, that takes xml_node and returns bool
* \return first node from subtree for which predicate returned true, or empty node
*/
template <typename Predicate> xml_node find_node(Predicate pred) const
{
if (!_root) return xml_node();
xml_node cur = first_child();
while (cur._root && cur._root != _root)
if (pred(cur)) return cur;
if (cur.first_child()) cur = cur.first_child();
else if (cur.next_sibling()) cur = cur.next_sibling();
else
while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
if (cur._root != _root) cur = cur.next_sibling();
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
}
}
return xml_node();
}
/**
* Find child node with the specified name that has specified attribute
*
* \param name - child node name
* \param attr_name - attribute name of child node
* \param attr_value - attribute value of child node
* \return first matching child node, or empty node
*/
xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
/**
* Find child node with the specified name that has specified attribute (use pattern matching for node name and attribute name/value)
*
* \param name - pattern for child node name
* \param attr_name - pattern for attribute name of child node
* \param attr_value - pattern for attribute value of child node
* \return first matching child node, or empty node
*
* \deprecated This function is deprecated
*/
PUGIXML_DEPRECATED xml_node find_child_by_attribute_w(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
/**
* Find child node that has specified attribute
*
* \param attr_name - attribute name of child node
* \param attr_value - attribute value of child node
* \return first matching child node, or empty node
*/
xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
/**
* Find child node that has specified attribute (use pattern matching for attribute name/value)
*
* \param attr_name - pattern for attribute name of child node
* \param attr_value - pattern for attribute value of child node
* \return first matching child node, or empty node
*
* \deprecated This function is deprecated
*/
PUGIXML_DEPRECATED xml_node find_child_by_attribute_w(const char_t* attr_name, const char_t* attr_value) const;
#ifndef PUGIXML_NO_STL
/**
* Get the absolute node path from root as a text string.
*
* \param delimiter - delimiter character to insert between element names
* \return path string (e.g. '/bookstore/book/author').
*/
string_t path(char_t delimiter = '/') const;
#endif
/**
* Search for a node by path.
* \param path - path string; e.g. './foo/bar' (relative to node), '/foo/bar' (relative
* to root), '../foo/bar'.
* \param delimiter - delimiter character to use while tokenizing path
* \return matching node, if any; empty node otherwise
*/
xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
/**
* Recursively traverse subtree with xml_tree_walker
* \see xml_tree_walker::begin
* \see xml_tree_walker::for_each
* \see xml_tree_walker::end
*
* \param walker - tree walker to traverse subtree with
* \return traversal result
*/
bool traverse(xml_tree_walker& walker);
#ifndef PUGIXML_NO_XPATH
/**
* Select single node by evaluating XPath query
*
* \param query - query string
* \return first node from the resulting node set by document order, or empty node if none found
*/
xpath_node select_single_node(const char_t* query) const;
/**
* Select single node by evaluating XPath query
*
* \param query - compiled query
* \return first node from the resulting node set by document order, or empty node if none found
*/
xpath_node select_single_node(const xpath_query& query) const;
/**
* Select node set by evaluating XPath query
*
* \param query - query string
* \return resulting node set
*/
xpath_node_set select_nodes(const char_t* query) const;
/**
* Select node set by evaluating XPath query
*
* \param query - compiled query
* \return resulting node set
*/
xpath_node_set select_nodes(const xpath_query& query) const;
#endif
/// \internal Document order or 0 if not set
arseny.kapoulkine
committed
const void* document_order() const;
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
/**
* Print subtree to writer
*
* \param writer - writer object
* \param indent - indentation string
* \param flags - formatting flags
* \param encoding - encoding used for writing
* \param depth - starting depth (used for indentation)
*/
void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
#ifndef PUGIXML_NO_STL
/**
* Print subtree to stream
*
* \param os - output stream
* \param indent - indentation string
* \param flags - formatting flags
* \param encoding - encoding used for writing
* \param depth - starting depth (used for indentation)
*/
void print(std::basic_ostream<char, std::char_traits<char> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
/**
* Print subtree to stream
*
* \param os - output stream
* \param indent - indentation string
* \param flags - formatting flags
* \param encoding - encoding used for writing
* \param depth - starting depth (used for indentation)
*/
void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;
#endif
/**
* Get node offset in parsed file/string (in bytes) for debugging purposes
*
* \return offset in bytes to start of node data, or -1 in case of error
* \note This will return -1 if node information changed to the extent that it's no longer possible to calculate offset, for example
* if element node name has significantly changed; this is guaranteed to return correct offset only for nodes that have not changed
* since parsing.
*/
ptrdiff_t offset_debug() const;
};
#ifdef __BORLANDC__
// Borland C++ workaround
bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
#endif
/**
* Child node iterator.
* It's a bidirectional iterator with value type 'xml_node'.
*/
class PUGIXML_CLASS xml_node_iterator
{
friend class xml_node;
private:
xml_node _wrap;
xml_node _parent;
/// \internal Initializing constructor
xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);
public:
/**
* Iterator traits
*/
typedef ptrdiff_t difference_type;
typedef xml_node value_type;
typedef xml_node* pointer;
typedef xml_node& reference;
#ifndef PUGIXML_NO_STL
typedef std::bidirectional_iterator_tag iterator_category;
#endif
/**
* Default constructor
*/
xml_node_iterator();
/**
* Initializing constructor
*
* \param node - node that iterator will point at
*/
xml_node_iterator(const xml_node& node);
/**
* Check if this iterator is equal to \a rhs
*
* \param rhs - other iterator
* \return comparison result
*/
bool operator==(const xml_node_iterator& rhs) const;
/**
* Check if this iterator is not equal to \a rhs
*
* \param rhs - other iterator
* \return comparison result
*/
bool operator!=(const xml_node_iterator& rhs) const;
/**
* Dereferencing operator
*
* \return reference to the node iterator points at
*/
xml_node& operator*();
/**
* Member access operator
*
* \return pointer to the node iterator points at
*/
xml_node* operator->();
/**
* Pre-increment operator
*
* \return self
*/
const xml_node_iterator& operator++();
/**
* Post-increment operator
*
* \return old value
*/
xml_node_iterator operator++(int);
/**
* Pre-decrement operator
*
* \return self
*/
const xml_node_iterator& operator--();
/**
* Post-decrement operator
*
* \return old value
*/
xml_node_iterator operator--(int);
};
/**
* Attribute iterator.
* It's a bidirectional iterator with value type 'xml_attribute'.
*/
class PUGIXML_CLASS xml_attribute_iterator
{
friend class xml_node;
private:
xml_attribute _wrap;
xml_node _parent;
/// \internal Initializing constructor
xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);
public:
/**
* Iterator traits
*/
typedef ptrdiff_t difference_type;
typedef xml_attribute value_type;
typedef xml_attribute* pointer;
typedef xml_attribute& reference;
#ifndef PUGIXML_NO_STL
typedef std::bidirectional_iterator_tag iterator_category;
#endif
/**
* Default constructor
*/
xml_attribute_iterator();
/**
* Initializing constructor
*
* \param attr - attribute that iterator will point at
* \param parent - parent node of the attribute
*/
xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
/**
* Check if this iterator is equal to \a rhs
*
* \param rhs - other iterator
* \return comparison result
*/
bool operator==(const xml_attribute_iterator& rhs) const;
/**
* Check if this iterator is not equal to \a rhs
*
* \param rhs - other iterator
* \return comparison result
*/
bool operator!=(const xml_attribute_iterator& rhs) const;
/**
* Dereferencing operator
*
* \return reference to the node iterator points at
*/
xml_attribute& operator*();
/**
* Member access operator
*
* \return pointer to the node iterator points at
*/
xml_attribute* operator->();
/**
* Pre-increment operator
*
* \return self
*/
const xml_attribute_iterator& operator++();
/**
* Post-increment operator
*
* \return old value
*/
xml_attribute_iterator operator++(int);
/**
* Pre-decrement operator
*
* \return self
*/
const xml_attribute_iterator& operator--();
/**
* Post-decrement operator
*
* \return old value
*/
xml_attribute_iterator operator--(int);
};
/**
* Abstract tree walker class
* \see xml_node::traverse
*/
class PUGIXML_CLASS xml_tree_walker
{
friend class xml_node;
private:
int _depth;
protected:
/**
* Get node depth
*
* \return node depth
*/
int depth() const;
public:
/**
* Default constructor
*/
xml_tree_walker();
/**
* Virtual destructor
*/
virtual ~xml_tree_walker();
public:
/**
* Callback that is called when traversal of node begins.
*
* \return returning false will abort the traversal
*/
virtual bool begin(xml_node&);
/**
* Callback that is called for each node traversed
*
* \return returning false will abort the traversal
*/
virtual bool for_each(xml_node&) = 0;
/**
* Callback that is called when traversal of node ends.
*
* \return returning false will abort the traversal
*/
virtual bool end(xml_node&);
};
/**
* Struct used to distinguish parsing with ownership transfer from parsing without it.
* \see xml_document::parse
*/
struct transfer_ownership_tag {};
/**
* Parsing status enumeration, returned as part of xml_parse_result struct
*/
enum xml_parse_status
{
status_ok = 0, ///< No error
status_file_not_found, ///< File was not found during load_file()
status_io_error, ///< Error reading from file/stream
status_out_of_memory, ///< Could not allocate memory
status_internal_error, ///< Internal error occurred
status_unrecognized_tag, ///< Parser could not determine tag type
status_bad_pi, ///< Parsing error occurred while parsing document declaration/processing instruction (<?...?>)
status_bad_comment, ///< Parsing error occurred while parsing comment (<!--...-->)
status_bad_cdata, ///< Parsing error occurred while parsing CDATA section (<![CDATA[...]]>)
status_bad_doctype, ///< Parsing error occurred while parsing document type declaration
status_bad_pcdata, ///< Parsing error occurred while parsing PCDATA section (>...<)
status_bad_start_element, ///< Parsing error occurred while parsing start element tag (<name ...>)
status_bad_attribute, ///< Parsing error occurred while parsing element attribute
status_bad_end_element, ///< Parsing error occurred while parsing end element tag (</name>)
status_end_element_mismatch ///< There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
};
/**
* Parser result
*/
struct PUGIXML_CLASS xml_parse_result
{
/// Parsing status (\see xml_parse_status)
xml_parse_status status;
/// Last parsed offset (in bytes from file/string start)
ptrdiff_t offset;
/// Source document encoding
xml_encoding encoding;
/// Cast to bool operator
operator bool() const
{
return status == status_ok;
}
/// Get error description
const char* description() const;
};
/**
* Document class (DOM tree root).
* This class has non-copyable semantics (private copy constructor/assignment operator).
*/
class PUGIXML_CLASS xml_document: public xml_node
{
private:
char_t* _buffer;
char _memory[192];
xml_document(const xml_document&);
const xml_document& operator=(const xml_document&);
arseny.kapoulkine
committed
void reset();
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
void create();
void destroy();
xml_parse_result load_buffer_impl(void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own);
public:
/**
* Default constructor, makes empty document
*/
xml_document();
/**
* Destructor
*/
~xml_document();
public:
#ifndef PUGIXML_NO_STL
/**
* Load document from stream.
*
* \param stream - stream with XML data
* \param options - parsing options
* \param encoding - source data encoding
* \return parsing result
*/
xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
/**
* Load document from stream.
*
* \param stream - stream with XML data
* \param options - parsing options
* \return parsing result
*/
xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);
#endif
/**
* Load document from string. String has to be zero-terminated. No encoding conversions are applied.
*
* \param contents - input string
* \param options - parsing options
* \return parsing result
*/
xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
/**
* Parse the given XML string in-situ.
* The string is modified; you should ensure that string data will persist throughout the
* document's lifetime. Although, document does not gain ownership over the string, so you
* should free the memory occupied by it manually.
*
* \param xmlstr - read/write string with XML data
* \param options - parsing options
* \return parsing result
*
* \deprecated This function is deprecated and will be removed in future versions; use xml_document::load_buffer_inplace instead
*/
PUGIXML_DEPRECATED xml_parse_result parse(char* xmlstr, unsigned int options = parse_default);
/**
* Parse the given XML string in-situ (gains ownership).
* The string is modified; document gains ownership over the string, so you don't have to worry
* about it's lifetime.
* Call example: doc.parse(transfer_ownership_tag(), string, options);
*
* \param xmlstr - read/write string with XML data
* \param options - parsing options
* \return parsing result
*
* \deprecated This function is deprecated and will be removed in future versions; use xml_document::load_buffer_inplace_own instead
*/
PUGIXML_DEPRECATED xml_parse_result parse(const transfer_ownership_tag&, char* xmlstr, unsigned int options = parse_default);
/**
* Load document from file
*
* \param path - file path
* \param options - parsing options
* \param encoding - source data encoding
* \return parsing result
*/
xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
/**
* Load document from buffer
*
* \param contents - buffer contents
* \param size - buffer size in bytes
* \param options - parsing options
* \param encoding - source data encoding
* \return parsing result
*/
xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
/**
* Load document from buffer in-situ.
* The buffer is modified; you should ensure that buffer data will persist throughout the document's
* lifetime. Document does not gain ownership over the buffer, so you should free the buffer memory manually.
*
* \param contents - buffer contents
* \param size - buffer size in bytes
* \param options - parsing options
* \param encoding - source data encoding
* \return parsing result
*/
xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
/**
* Load document from buffer in-situ (gains buffer ownership).
* The buffer is modified; you should ensure that buffer data will persist throughout the document's
* lifetime. Document gains ownership over the buffer, so you should allocate the buffer with pugixml
* allocation function.
*
* \param contents - buffer contents
* \param size - buffer size in bytes
* \param options - parsing options
* \param encoding - source data encoding
* \return parsing result
*/
xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
/**
* Save XML to writer
*
* \param writer - writer object
* \param indent - indentation string
* \param flags - formatting flags
* \param encoding - encoding used for writing
*/
void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
#ifndef PUGIXML_NO_STL
/**
* Save XML to stream
*
* \param stream - output stream
* \param indent - indentation string
* \param flags - formatting flags
* \param encoding - encoding used for writing
*/
void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
/**
* Save XML to stream
*
* \param stream - output stream
* \param indent - indentation string
* \param flags - formatting flags
*/
void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
#endif
/**
* Save XML to file
*
* \param path - file path
* \param indent - indentation string
* \param flags - formatting flags
* \param encoding - encoding used for writing
* \return success flag
*/
bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
/**
* Compute document order for the whole tree
* Sometimes this makes evaluation of XPath queries faster.
*/
PUGIXML_DEPRECATED void precompute_document_order();
};
#ifndef PUGIXML_NO_XPATH
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
class xpath_ast_node;
class xpath_allocator;
/// XPath query return type classification
enum xpath_value_type
{
xpath_type_none, ///< Unknown type (query failed to compile)
xpath_type_node_set, ///< Node set (xpath_node_set)
xpath_type_number, ///< Number
xpath_type_string, ///< String
xpath_type_boolean ///< Boolean
};
/// XPath query return type classification
/// \deprecated This type is deprecated and will be removed in future versions; use xpath_value_type instead
typedef xpath_value_type xpath_type_t;
struct PUGIXML_CLASS xpath_parse_result
{
/// Error message (0 if no error)
const char* error;
/// Last parsed offset (in characters from string start)
ptrdiff_t offset;
/// Cast to bool operator
operator bool() const
{
return error == 0;
}
/// Get error description
const char* description() const;
};
/**
* A class that holds compiled XPath query and allows to evaluate query result
*/
class PUGIXML_CLASS xpath_query
{
private:
// Non-copyable semantics
xpath_query(const xpath_query&);
xpath_query& operator=(const xpath_query&);
xpath_allocator* _alloc;
xpath_ast_node* _root;
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
xpath_parse_result _result;
typedef xpath_ast_node* xpath_query::*unspecified_bool_type;
public:
/**
* Constructor from string with XPath expression.
* Throws xpath_exception on compilation error, std::bad_alloc on out of memory error.
*
* \param query - string with XPath expression
*/
explicit xpath_query(const char_t* query);
/**
* Destructor
*/
~xpath_query();
/**
* Get query expression return type
*
* \return expression return type
**/
xpath_value_type return_type() const;
/**
* Evaluate expression as boolean value for the context node \a n.
* If expression does not directly evaluate to boolean, the expression result is converted