Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have some XML that looks like this:
Which is valid XML. However, when parsed by
xmldoc
theval
property for thecontent:encoded
element is:'\n '
. This is because the white space (in this case'\n '
) emits atext
event in the SAX parser after acdata
event has already been emit. So thetext
event overrides thecdata
event even thoughisValCdata
is true. This behavior seems to be very fault intolerant for what is acceptable by most other XML parsers. As another note, this behavior also makes XML that looks like<a>b<c/>d</a>
very difficult to work with.This PR changes the behavior of this library so that comments, cdata, and text may all be treated as XML nodes similarly to the
XMLElement
object. Theval
property is still maintained for convenience by appending cdata and text values, but to get comments you now have to look at thechildren
array.The breaking changes that occur because of this change:
isValCData
orisValComment
. An element can have more then one child node type.val
. You can find them inchildren
instead.children
,firstChild
, andlastChild
properties may be a text, cdata, comment, or element object and not just an element object as they were in the past. To help filter out the objects you don’t want, use the newtype
property.If you only use the convenience methods, nothing should change for you.
There are simpler ways to fix the bug I expressed above, I just feel like this is an important change to make for the stability of this library given it may cause other bugs.
Thanks so much for your work, this is a great library 👍
[Edit by @nfarina]: Closes #23, #40