Giter Site home page Giter Site logo

Comments (3)

neslib avatar neslib commented on July 28, 2024

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.

Alekcvp avatar Alekcvp commented on July 28, 2024

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.

neslib avatar neslib commented on July 28, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.