FAQ
I've got some code that manually decodes XML using the xml.Decoder tokens
and unless I'm missing something there is no outside access to the line
number field for the Decoder. I only care about this when generating an
error message for display (it would be nice to report at least an
approximate line number to go along with the error message), so simply
having an exposed version of the syntaxError method would be sufficient for
my needs.

This is simple to workaround by just duplicating the xml package into my
own local package, but it would be nice if I could just use the std package
in some future version of the Go std lib and this seems like a harmless
(and useful in many cases) thing to expose.

Thanks!

--

Search Discussions

  • Minux at Oct 12, 2012 at 5:32 am

    On Fri, Oct 12, 2012 at 12:18 PM, George McBay wrote:

    I've got some code that manually decodes XML using the xml.Decoder tokens
    and unless I'm missing something there is no outside access to the line
    number field for the Decoder. I only care about this when generating an
    error message for display (it would be nice to report at least an
    approximate line number to go along with the error message), so simply
    having an exposed version of the syntaxError method would be sufficient for
    my needs.
    IIRC, the reason it's not exposed is that the line number might not be
    accurate?

    --
  • George McBay at Oct 12, 2012 at 7:19 am
    Well, line numbers for XML documents are inherently wonky. If you have an
    error because the document is missing a required attribute on a
    startelement and the startelement spans multiple lines, which line do you
    report the error on? IMO it doesn't matter as long as the reported line
    number is in the general range expected plus or minus a few lines. In my
    usage thus far, the line number the decoder increments is good enough to be
    useful for my purposes, I just can't access it outside of the package
    without duplicating the package to make my own accessor. Also the xml
    package itself uses the line number when reporting syntax errors. I just
    want to be able to generate my own errors for situations where the xml is
    well formed but breaks some document-specific constraint.

    On Thursday, October 11, 2012 10:32:48 PM UTC-7, minux wrote:


    On Fri, Oct 12, 2012 at 12:18 PM, George McBay <george...@gmail.com<javascript:>
    wrote:
    I've got some code that manually decodes XML using the xml.Decoder tokens
    and unless I'm missing something there is no outside access to the line
    number field for the Decoder. I only care about this when generating an
    error message for display (it would be nice to report at least an
    approximate line number to go along with the error message), so simply
    having an exposed version of the syntaxError method would be sufficient for
    my needs.
    IIRC, the reason it's not exposed is that the line number might not be
    accurate?
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 12, '12 at 4:18a
activeOct 12, '12 at 7:19a
posts3
users2
websitegolang.org

2 users in discussion

George McBay: 2 posts Minux: 1 post

People

Translate

site design / logo © 2021 Grokbase