TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
Representation of a "running" XML document which is displayed on the fly. More...
#include <tsxmlRunningDocument.h>
Public Member Functions | |
RunningDocument (Report &report=(ts::NullReport::Instance())) | |
Constructor. | |
virtual | ~RunningDocument () override |
Destructor. | |
size_t | childrenCount () const |
Get the number of children. | |
virtual void | clear () |
Clear the content of the node. | |
virtual Node * | clone () const override |
Clone the content of the node in a dynamically allocated object. | |
void | close () |
Close the running document. | |
UString | debug () const |
Build a debug string for the node. | |
size_t | depth () const |
Get the depth of an XML element. | |
Document * | document () |
Get the document into which the node is located. | |
const Document * | document () const |
Get the document into which the node is located. | |
Node * | firstChild () |
Get the first child of a node. | |
const Node * | firstChild () const |
Get the first child of a node. | |
Element * | firstChildElement () |
Get the first child Element of a node. | |
const Element * | firstChildElement () const |
Get the first child Element of a node. | |
void | flush () |
Flush the running document. | |
bool | hasChildren () const |
Check if the node has children. | |
Element * | initialize (const UString &rootName, const UString &declaration=UString()) |
Initialize the document. | |
Node * | lastChild () |
Get the last child. | |
const Node * | lastChild () const |
Get the last child. | |
size_t | lineNumber () const |
Get the line number in input document. | |
bool | load (const UString &fileName, bool search=true) |
Load and parse an XML file. | |
bool | load (std::istream &strm) |
Load and parse an XML file. | |
void | move (Node *newSibling, bool before) |
Move the node before or after another node, potentially to a new parent. | |
void | moveAfter (Node *newSibling) |
Move the node after another node, potentially to a new parent. | |
void | moveBefore (Node *newSibling) |
Move the node before another node, potentially to a new parent. | |
Node * | nextSibling () |
Get the next sibling node. | |
const Node * | nextSibling () const |
Get the next sibling node. | |
Element * | nextSiblingElement () |
Find the next sibling element. | |
const Element * | nextSiblingElement () const |
Find the next sibling element. | |
virtual UString | oneLiner () const |
Format the value as a one-liner XML text. | |
Element * | open (const UString &rootName, const UString &declaration=UString(), const fs::path &fileName=fs::path(), std::ostream &strm=std::cout) |
Initialize the running document. | |
Node * | parent () |
Get the parent's node. | |
const Node * | parent () const |
Get the parent's node. | |
bool | parse (const UString &text) |
Parse an XML document. | |
bool | parse (const UStringList &lines) |
Parse an XML document. | |
bool | preserveSpace () const |
Check if the node or one of its ancestors has attribute xml:space="preserve". | |
Node * | previousSibling () |
Get the previous sibling node. | |
const Node * | previousSibling () const |
Get the previous sibling node. | |
Element * | previousSiblingElement () |
Find the previous sibling element. | |
const Element * | previousSiblingElement () const |
Find the previous sibling element. | |
virtual void | print (TextFormatter &output, bool keepNodeOpen=false) const override |
Format the node for an output XML document. | |
virtual void | printClose (TextFormatter &output, size_t levels=std::numeric_limits< size_t >::max()) const override |
Print the closing tags for the node. | |
void | removeComments (bool recurse) |
Remove all comments in the XML node. | |
void | reparent (Node *newParent, bool last=true) |
Attach the node to a new parent. | |
Report & | report () const |
Get a reference to the report object for the XML node. | |
bool | ringAlone () const |
Check if the node is alone in its own ring. | |
void | ringInsertAfter (RingNode *o) |
Insert this object in a ring after the specified node. | |
void | ringInsertBefore (RingNode *o) |
Insert this object in a ring before the specified node. | |
template<typename T > | |
T * | ringNext () |
Get the next node in the ring. | |
template<typename T > | |
const T * | ringNext () const |
Get the next node in the ring. | |
template<typename T > | |
T * | ringPrevious () |
Get the previous node in the ring. | |
template<typename T > | |
const T * | ringPrevious () const |
Get the previous node in the ring. | |
void | ringRemove () |
Remove the node from the ring it belongs to and creates its own ring. | |
size_t | ringSize () const |
Count the number of element in the ring. | |
void | ringSwap (RingNode *o) |
Swap this object and another one in their rings. | |
Element * | rootElement () |
Get the root element of the document. | |
const Element * | rootElement () const |
Get the root element of the document. | |
bool | save (const fs::path &fileName, size_t indent=2) |
Save an XML file. | |
void | setTweaks (const Tweaks &tw) |
Set the global XML parsing and formatting tweaks for the document. | |
void | setValue (const UString &value) |
Set the value of the node. | |
virtual bool | stickyOutput () const |
Check if the text shall be stuck to other elements in XML output. | |
virtual UString | toString () const override |
Convert to a string object. | |
virtual const Tweaks & | tweaks () const override |
Get a constant reference to the global XML parsing and formatting tweaks for the document. | |
virtual UString | typeName () const override |
Return a node type name, mainly for debug purpose. | |
const UString & | value () const |
Get the value of the node. | |
Static Public Member Functions | |
static UString | DisplayFileName (const UString &name, bool stdInputIfEmpty=false) |
Get a suitable display name for an XML file name or inline content. | |
static bool | IsInlineXML (const UString &name) |
Check if a "file name" is in fact inline XML content instead of a file name. | |
Protected Member Functions | |
Node * | identifyNextNode (TextParser &parser) |
Identify the next token in the document. | |
virtual bool | parseChildren (TextParser &parser) |
Parse children nodes and add them to the node. | |
virtual bool | parseNode (TextParser &parser, const Node *parent) override |
Parse the node. | |
void | setPreserveSpace (bool on) |
Called by the subclass when its spaces shall be preserved. | |
Representation of a "running" XML document which is displayed on the fly.
The idea is to display or save an XML document which is built element by element without waiting for the end of the document. Moreover, considering that the document can be arbitrary long, can take an arbitrary long time to be built and is not used for anything else than display or save, elements are destroyed after being displayed or saved to avoid wasting memory.
|
explicit |
Constructor.
[in,out] | report | Where to report errors. |
Element * ts::xml::RunningDocument::open | ( | const UString & | rootName, |
const UString & | declaration = UString() , |
||
const fs::path & | fileName = fs::path() , |
||
std::ostream & | strm = std::cout |
||
) |
Initialize the running document.
The initial declaration and root are created. The output XML file is initialized but nothing is printed yet.
[in] | rootName | Name of the root element to create. |
[in] | declaration | Optional XML declaration. When omitted or empty, the standard declaration is used, specifying UTF-8 as format. |
[in] | fileName | Output file name to create. When empty or "-", strm is used for output. |
[in,out] | strm | The default output text stream when fileName is empty or "-". The referenced stream object must remain valid as long as this object. |
void ts::xml::RunningDocument::flush | ( | ) |
Flush the running document.
All elements under the document root are displayed or saved and then deleted. The XML document header is issued with the first element. The XML structure is left open for more elements, in the next call to flush().
void ts::xml::RunningDocument::close | ( | ) |
Close the running document.
If the XML structure is still open, it is closed. The output file, if any, is closed.
|
inherited |
Parse an XML document.
[in] | lines | List of text lines forming the XML document. |
|
inherited |
Parse an XML document.
[in] | text | The XML document. |
|
inherited |
Load and parse an XML file.
[in] | fileName | Name of the XML file to load. If fileName is empty or "-", read the standard input. If fileName starts with "<?xml", this is considered as "inline XML content". The document is loaded from this string instead of reading a file. |
[in] | search | If true, search the XML file in the TSDuck configuration directories if fileName is not found and does not contain any directory part. |
|
inherited |
Load and parse an XML file.
[in,out] | strm | A standard text stream in input mode. |
|
inherited |
Save an XML file.
[in] | fileName | Name of the XML file to save. If fileName is empty or "-", writes to the standard output. |
[in] | indent | Indentation width of each level. |
|
staticinherited |
Check if a "file name" is in fact inline XML content instead of a file name.
[in] | name | A file name string. |
|
staticinherited |
Get a suitable display name for an XML file name or inline content.
[in] | name | A file name string. |
[in] | stdInputIfEmpty | If true and if fileName is empty, reads the standard input. |
|
inlineinherited |
Get the root element of the document.
|
inlineinherited |
Get the root element of the document.
|
inherited |
Initialize the document.
The initial declaration and root are created.
[in] | rootName | Name of the root element to create. |
[in] | declaration | Optional XML declaration. When omitted, the standard declaration is used, specifying UTF-8 as format. |
|
overridevirtualinherited |
Get a constant reference to the global XML parsing and formatting tweaks for the document.
Reimplemented from ts::xml::Node.
|
inlineinherited |
Set the global XML parsing and formatting tweaks for the document.
[in] | tw | The new global XML tweaks. |
|
overridevirtualinherited |
Convert to a string object.
Implements ts::StringifyInterface.
|
overridevirtualinherited |
Clone the content of the node in a dynamically allocated object.
This virtual method must be implemented by subclasses to allocate a object of the right class.
Implements ts::xml::Node.
|
overridevirtualinherited |
|
overridevirtualinherited |
Format the node for an output XML document.
[in,out] | output | The output object to format the XML document. |
[in] | keepNodeOpen | If true, keep the node open so that children may be printed later. |
Implements ts::xml::Node.
|
overridevirtualinherited |
Print the closing tags for the node.
Typically used after print() when keepNodeOpen was true. The default implementation is to do nothing. Subclasses may replace this.
[in,out] | output | The output object to format the XML document. |
[in] | levels | Number of levels to close. By default, close the complete document. If zero, no output is produced. |
Reimplemented from ts::xml::Node.
|
overrideprotectedvirtualinherited |
Parse the node.
[in,out] | parser | The document parser. On input, the current position of the parser after the tag which identified the node ("<?", "<!- -", etc.) On output, it must be after the last character of the node. |
[in] | parent | Candidate parent node, for information only, do not modify. Can be null. |
Implements ts::xml::Node.
|
inlineinherited |
Get the line number in input document.
|
virtualinherited |
Clear the content of the node.
The node becomes empty but remains attached to its parent.
Reimplemented in ts::xml::Element.
|
inherited |
Attach the node to a new parent.
The node is first detached from its previous parent.
[in,out] | newParent | New parent. If zero, the node becomes orphan. In that case, the node will no longer be freed by its parent and must be explicitly deleted. |
[in] | last | If true, the child is added at the end of the list of children. If false, it is added at the beginning. |
|
inlineinherited |
Move the node before another node, potentially to a new parent.
[in,out] | newSibling | A new sibling. The node will be moved before this one. |
|
inlineinherited |
Move the node after another node, potentially to a new parent.
[in,out] | newSibling | A new sibling. The node will be moved after this one. |
|
inherited |
Move the node before or after another node, potentially to a new parent.
[in,out] | newSibling | A new sibling. The node will be moved before or after this one. |
[in] | before | If true, move the node before newSibling, after it otherwise. |
|
inlineinherited |
Get the parent's node.
|
inlineinherited |
Get the parent's node.
|
inlineinherited |
Get the document into which the node is located.
|
inherited |
Get the document into which the node is located.
|
inherited |
Get the depth of an XML element.
|
inherited |
Check if the node or one of its ancestors has attribute xml:space="preserve".
|
inlineinherited |
Check if the node has children.
|
inlineinherited |
Get the number of children.
|
inlineinherited |
Get the first child of a node.
|
inlineinherited |
Get the first child of a node.
|
inlineinherited |
Get the last child.
|
inlineinherited |
Get the last child.
|
inlineinherited |
Get the next sibling node.
|
inherited |
Get the next sibling node.
|
inlineinherited |
Get the previous sibling node.
|
inherited |
Get the previous sibling node.
|
inlineinherited |
|
inherited |
|
inlineinherited |
Find the next sibling element.
|
inherited |
Find the next sibling element.
|
inlineinherited |
Find the previous sibling element.
|
inherited |
Find the previous sibling element.
|
inlineinherited |
Get the value of the node.
The semantic of the value depends on the node subclass:
|
inlineinherited |
|
inherited |
Remove all comments in the XML node.
[in] | recurse | If true, apply recursively to all children nodes. |
|
virtualinherited |
Format the value as a one-liner XML text.
|
virtualinherited |
Check if the text shall be stuck to other elements in XML output.
Reimplemented in ts::xml::Text.
|
inherited |
Build a debug string for the node.
|
inlineinherited |
Get a reference to the report object for the XML node.
|
protectedinherited |
Identify the next token in the document.
[in,out] | parser | The document parser. |
|
protectedvirtualinherited |
Parse children nodes and add them to the node.
Stop either at end of document or before a "</" sequence or on error.
[in,out] | parser | The document parser. |
|
inlineprotectedinherited |
Called by the subclass when its spaces shall be preserved.
Typically called when xml:space="preserve" is encountered.
[in] | on | True is spaces shall be preserved. |
|
inlineinherited |
Check if the node is alone in its own ring.
|
inherited |
Insert this object in a ring after the specified node.
[in] | o | A node of a ring. This object is inserted after o in the ring. |
|
inherited |
Insert this object in a ring before the specified node.
[in] | o | A node of a ring. This object is inserted before o in the ring. |
|
inherited |
Swap this object and another one in their rings.
If the two objects belong to the same ring, their positions are swapped. If they belong to distinct rings, they also move to each other's ring.
[in] | o | The node to swap with. |
|
inlineinherited |
Get the next node in the ring.
T | A superclass of RingNode, the expected type of the next object in the ring. |
|
inlineinherited |
Get the next node in the ring.
T | A superclass of RingNode, the expected type of the next object in the ring. |
|
inlineinherited |
Get the previous node in the ring.
T | A superclass of RingNode, the expected type of the previous object in the ring. |
|
inlineinherited |
Get the previous node in the ring.
T | A superclass of RingNode, the expected type of the previous object in the ring. |
|
inherited |
Count the number of element in the ring.
Warning: This method has a linear response time, avoid using it when possible.