Comments (6)
Hey Titus!
Adding whole-string offset info to nodes would probably be pretty easy since the offset is already available during parsing, but line and column positions are currently only calculated when an error occurs (and not very efficiently).
There are currently several places where the parser consumes newlines, so keeping track of the line and column efficiently would probably take some refactoring. I'm open to this in theory, but I'm concerned about the potential performance impact given that many users aren't likely to need this functionality. I haven't looked into it deeply though, so I'm mostly working from memory.
from parse-xml.
Byte offsets into the source document is good enough for me!
from parse-xml.
https://github.com/vfile/vfile-location can do the transform! Should be more efficient that the current algorithm for errors, as it does most of the work once upfront, but it would likely still be faster to track everything directly when parsing
from parse-xml.
If you’re worried about performance (which makes sense), this could be put behind an option.
When that option is turned on, vfile-location
is used at the start to generate the index, and then later for each start/end of a node you can do if (options.position) location.toPosition(byteOffset)
or so?
I think that for me the perf “bottle neck” is fine
from parse-xml.
True. Unfortunately, integrating vfile-location into parse-xml would mean adding several runtime dependencies. Having zero runtime dependencies is one of parse-xml's differentiating features, and I'd prefer to preserve that.
One alternative might be to add events or callback hooks that would give vfile-location (or anything else) an opportunity to annotate nodes during parsing. Then this optional behavior could be part of a higher level package without requiring parse-xml itself to add any dependencies.
Or, if parse-xml were to annotate each node with its string offset, maybe another option would be for a higher level package to traverse the node tree after parsing and use vfile-location at that point?
from parse-xml.
@wooorm How does this look? #25
from parse-xml.
Related Issues (18)
- Consider adding opt-in support for parsing XML 1.1 HOT 3
- RegExp issue with very long attributes HOT 1
- Does it support running in WebWorkers? HOT 2
- Very cool lib HOT 1
- Question "claims to test an illegal char, but tests the wrong char" HOT 3
- xml.replace is not a function HOT 1
- Serialising back to XML
- Documentation says second argument is optional, but TS compiler says its required HOT 3
- Include additional structured information in error objects HOT 7
- Add type information for errors
- Don't trim comment content
- Text content following CDATA is appended to a preceding `XmlCdata` node
- Option to ignore missing ends HOT 1
- Optionally include XML declarations and doctype declarations in the DOM
- Streams HOT 2
- 
 is interpreted as space instead of line feed HOT 3
- Parsing can hang on attributes with many references
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 parse-xml.