Fix errors caused by undefined and text nodes

- Ignore undefined nodes
- Don't try to set the parent for undefined or string nodes