XML DOMLesson 42Free preview
DOM Create Nodes
This lesson is part of XML · All levels
Summary
New nodes are created with createElement for elements, createAttribute for attributes, and createTextNode for text. The output of the creation has not been connected to the tree so it must be added with an appendChild or insertBefore. This pattern allows you to build dynamic parts of a document according to the data.
Key points
- CreateElement creates an empty element that is not yet installed
- CreateAttribute sets up attributes with a specific name
- CreateTextNode wrapped text as a text node
- New nodes have to be added to the tree to make it appear.
- The formation of nodes supports dynamically growing documents
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.