Skip to content

Add support for adding sibling elements in a way which preserves order #111

@jakraft

Description

@jakraft

Problem

Currently, the only way to add a sibling element is to append a child element to its parent:

currentElement.up().ele("siblingElement");

This works great if you're building a new XML document from scratch, but it makes it impossible to update an existing XML document in a manner which preserves order. Consider the following document:

<parent>
  <child1 />
  <child2 />
</parent>

If currentElement points to <child1 />, calling .up().ele("siblingElement") would result in this output:

<parent>
  <child1 />
  <child2 />
  <siblingElement />
</parent>

Proposal

Add two new methods, eleBefore and eleAfter, which would add a sibling element before/after the current element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions