Content
Content can be either other Element(s) or Text.
For the xml
<foo>
<Bar note='Some text'</Bar>
<Baz note='More stuff'</Baz>
</foo>
…you can do something like this:
e <- Element$new("foo")$addContent(
Element$new("Bar")$setAttribute("note", "Some text")
)$addContent(
Element$new("Baz")$setAttribute("note", "More stuff")
)
e
#> <foo><Bar note='Some text'></Bar><Baz note='More stuff'></Baz></foo>
To retrieve content there are several ways:
- getContent() This will get you the complete list of content regardless if they are Elements or Text nodes.
- getChildren() This will give you a list of Elements belonging to this element.
- removeContent(content) This will remove the content supplied from this Elements content list.
- removeContentAt(index) Same as above but for the position in the list matching the index supplied.
- contentIndex(content) Gives you the index of the content supplied or -1 if no content was found.
- getChild(name) Gives you the first occurrence of the Element that is a child of this element with the name matching the name supplied
- hasContent() TRUE if there is any content belonging to this element
- hasChildren() TRUE if there is any child elements for this element