Comments (3)
I didn't add a helper method for this because there are different interpretations of what the text of an element actually is, and I didn't want any confusion.
In your example code, you only return the text of the first child of type Text. But that is not what other people may expect. What if an element has multiple text child nodes (maybe with other elements in between)? Should we concatenate the texts of all these child nodes together, and should we put spaces between them if needed? What if some of the child nodes have their own children? Should those children (and grandchildren etc.) also be included in the text?
There is no straightforward solution here, which is why I didn't implement this. What do you think is the most logical interpretation of such a property? Maybe I can make an implementation for that.
from neslib.xml.
What do you think is the most logical interpretation of such a property?
As I understand the standard text is not a separate element, but part of the parent one (just like an attribute).
An element can contain:
text
attributes
other elements
or a mix of the above
From my point of view, it would be convenient to have some .Text property containing all text fragments of the given element, combined by a space, for example. But you can also leave the current text nodes for those who care about exactly how the text is located relative to other elements. The text inside other (nested) elements belongs to those elements.
from neslib.xml.
I added a TXmlNode.Text
property. For Text, CData and Comment nodes, it returns the same as the Value
property. For Element nodes, it returns a concatenation of all direct children of type Text or CData (with spaces added if needed).
from neslib.xml.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neslib.xml.