Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some support for xml mixed content processing #60

Closed
wants to merge 2 commits into from
Closed

Adding some support for xml mixed content processing #60

wants to merge 2 commits into from

Conversation

rupor-github
Copy link

@rupor-github rupor-github commented Dec 9, 2018

The idea is to move processing a bit closer to python's lxml - allowing for simpler xml mixed content processing. The only possible "breaking" change is resulting indentation - I had to rewrite indenting code removing superficial CharData items.

@beevik
Copy link
Owner

beevik commented Jan 9, 2019

I'm uncomfortable with the API change this PR imposes on etree. It takes it further away from the original python etree implementation, and I'm not sure what it makes easier.

Could you help me better understand how this change improves etree? It should already be possible to examine all character data tokens between elements, since they are represented as character data children of their parent elements.

@beevik
Copy link
Owner

beevik commented Jan 9, 2019

Oops, I was actually wrong about this:

It takes it further away from the original python etree implementation, and I'm not sure what it makes easier.

It's been a long time since I used python's etree, but it does expose a tail property on elements. Is this the behavior you were trying to introduce in this etree library?

Unfortunately, your pull request represents an API breaking change. Consider the following XML:

<a> <b/> </a>

In the current etree implementation, there are 3 child tokens of element a:

  1. a character data token with a single space.
  2. a child element named b.
  3. another character data token with a single space.

In your implementation, there are only 2 child tokens of element a:

  1. a character data token with a single space.
  2. a child element named b with a tail of a single space.

Unfortunately, any code that depends on iterating all child elements and finding trailing character data tokens will break under your change.

Perhaps this is something I could consider for a 2.0 release of etree, but for now I hope you will understand why I cannot accept it.

@beevik beevik closed this Jan 9, 2019
@rupor-github
Copy link
Author

Sure, no problem. Just keep in mind that presently if somebody wants to handle "mixed" - there is no API to do so -- unless you want to operate on "InsertChild" level and always iterate all nodes looking for text, which is a bit involving...

@beevik
Copy link
Owner

beevik commented Jan 12, 2019

I agree; it is sort of a pain right now. I wonder if there might be another way to address the ease-of-use issue without breaking the existing API. On the read side of things, perhaps an element Tail method could be used to return the contents of the trailing text immediately following the element. Similarly, an AddTail method could be used to insert a trailing character data token immediately after the element. This approach would have the advantage of making it easier to deal without tail text but without modifying the data currently stored with each element.

I'm going to give this more thought.

@beevik
Copy link
Owner

beevik commented Jan 26, 2019

@rupor-github I added support for Tail and SetTail in a way that doesn't break backward compatibility. Please see 1d33bca

Thanks for the original pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants