From OpenSCADAWiki
XML node-tag object (XMLNodeObj)
Functions:
- string name( ) — the name of the node, XML-tag.
- string text( bool full = false ) — the text of the node, contents of the XML-tag. Set full for get the combined text of all included nodes.
- string attr( string id ) — the value of the node attribute id.
- XMLNodeObj setName( string vl ) — sets of the node name to vl. Returns the current node.
- XMLNodeObj setText( string vl ) — sets of the node text to vl. Returns the current node.
- XMLNodeObj setAttr( string id, string vl ) — sets the attribute id to the value vl. Returns the current node.
- XMLNodeObj clear( bool full = false ) — clears the node for the childs, removes the text and attributes for full.
- int childSize( ) — quantity of the included nodes.
- XMLNodeObj childAdd( ElTp no = XMLNodeObj ); XMLNodeObj childAdd( string no ) — addition of the object no as the included one. no may be the direct object-result of the function "SYS.XMLNode()", and the string with the name of a new tag. Returns the included node.
- XMLNodeObj childIns( int id, ElTp no = XMLNodeObj ); XMLNodeObj childIns( int id, string no ) — insert of the object no as the included one to the position id. no may be the direct object-result of the function "SYS.XMLNode()", and the string with the name of a new tag. Returns the embedded node.
- XMLNodeObj childDel( int id ) — deletes the included node from the position id. Returns current node.
- XMLNodeObj childGet( int id ) — gets the included node in the position id. Returns 0 at missing one.
- XMLNodeObj childGet( string name, int num = 0 ) — gets the included node with the tag name and the position number num. Returns 0 at missing one.
- XMLNodeObj parent( ) — gets the parent node. Returns false at missing one.
- string load( string str, bool file = false, int flg = 0, string cp = "UTF-8" ) — loads the XML from the string str or from the file with the path in str if the file equal "true", with the source encoding cp. Returns a string with error in the format "{errCod}:{errText}", which is "0" for successful loading. Where flg — loading flags:
- 0x01 — full loading, with texts and comments blocks into special nodes;
- 0x02 — don't remove spaces from the begin and end of the tag text;
- 0x04 — process for specific the pure HTML like to: tags without closing, attributes without a value, attribute values without quoting, closing tags switching; sets already from the DOCTYPE HTML header.
- string save( int flg = 0, string path = "", string cp = "UTF-8" ) — saves the XML tree to the string or to the file path with the formatting flags flg and target encoding cp. Returns the XML text or the error code. The following formatting options flg are provided:
- 0x01 — break before the open tag;
- 0x02 — break after the open tag;
- 0x04 — break after the close tag;
- 0x08 — break after the text;
- 0x10 — break after the special block;
- 0x1E — break after all;
- 0x20 — include standard XML header;
- 0x40 — include standard XHTML header;
- 0x80 — clean the service tags: <??>, <!-- -->;
- 0x100 — omit for tag's name encoding;
- 0x200 — omit for attribute's name encoding;
- 0x400 — shield the binary symbols [\x0-\x8\xB-\xC\x0E-\x1F] and wrong UTF-8;
- 0x800 — hold empty attributes, mostly as the sign in the pure HTML.
- XMLNodeObj getElementBy( string val, string attr = "id" ) — gets an element from the tree by the attribute attr in value val, returns null-EVAL at missing requesting element.
- TArrayObj<XMLNodeObj> getElementsBy( string tag, string attrVal = "", string attr = "id", int limit = 0, int from = 0 ) — gets an elements array from the tree by the tag (empty for all) and attribute attr in value attrVal (empty for pass), also starting the tag number from and limiting them number in limit (zero for no limit).