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 — does not remove spaces from the begin and end of the tag text.
- 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 — end line before the opening tag;
- 0x02 — end line after the opening tag;
- 0x04 — end line after the closing tag;
- 0x08 — end line after the text;
- 0x10 — end line after the instruction;
- 0x1E — end line after all ones;
- 0x20 — inserts the standard XML-header;
- 0x40 — inserts the standard XHTML-header;
- 0x80 — cleans the service tags: <??>, <!-- -->;
- 0x100 — does not encode the tag name;
- 0x200 — does not encode the attribute;
- 0x400 — shield the binary symbols [\x0-\x8\xB-\xC\x0E-\x1F] and wrong UTF-8.
- XMLNodeObj getElementBy( string val, string attr = "id" ) — gets an element from the tree by the attribute attr in value val.
- 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).