-
Notifications
You must be signed in to change notification settings - Fork 20
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
How do I read a node that has a text value and child elements? #30
Comments
Possibly related to #24? |
I think the root problem is the way stringReader handles nodes that have a text element and children elements which I think is tied to how |
But what should the behaviour be? should it use the concatenation of all text nodes that are direct children (but not descendents), use just the first text node, fail if there are element node children, or use a concatenation of all descendent text nodes (as is currently done)? Changing the default way from the current behaviour is probably a breaking change, although I'm not sure if any existing usages make use of the current behaviour in the presence of child elements. I'm not necessarily opposed to changing the default way of parsing text. But to be honest, I kind of think that failing if there are child elements makes the most sense to me as the default. I pointed at #24 because it is a more general solution, though perhaps not as convenient in your case. I could probably add something to extract the first text node or all direct child text nodes to the XPath and/or XmlReader API. Although I'm not sure what good names for those methods would be. Would that work for you? |
You know, I may have forgotten an XML element could have multiple text nodes. I think you're making a lot of sense then. Trying to read a node with children as a string is probably undefined behaviour. I think a solution that returned either the direct child text nodes or all child nodes makes sense and then the user can do a |
I have an XML element that looks like
that I'm trying to write an XmlReader for. My case class looks like:
The problem I'm having is trying to extract the card number. I've played around on the REPL and looked at the source code. My first thought was I could just read the root element
This is reading everything under the root node though. My next thought was maybe I could loop through the child nodes:
but that doesn't return the text node. My last thought was what if
<Card>
wasn't the root element. Would that change anything:So that seems to be giving the same behavior. It looks like under the hood stringReader is using the
text
function onNodeSeq
It looks like this behavior comes from there
The text was updated successfully, but these errors were encountered: