FAQ
Hello,

I'm having a little trouble parsing XML. I'm trying to parse output from
Dell's SOAP inventory service
(see http://xserv.dell.com/services/assetservice.asmx?op=GetAssetInformation).
My example program tries to pull out relevant info and print out
CSV-formatted lines for each service agreement:

     http://play.golang.org/p/nJSBNyCaXB

There's a number of things I'm unsure about:

- I'm reading a sub-element of the XML. Do I have to specify its parents in
a tag somewhere?
- Should I specify the namespace in every element, just the containing
elements, or at all?
- When parsing nested XML, should I tag the field in the containing struct,
or put an XMLname field in the substruct?

Unfortunately I have to parse a lot of nasty XML at my job. I would love to
be able to use Go to do it.

Cheers,
David

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Phil at May 22, 2013 at 12:06 am
    Hi,

    As far as I can see when parsing (unmarshalling) XML you need to describe
    the entire schema of the XML document, I've knocked up a quick example here
    using the xml data file you have in your
    example, http://play.golang.org/p/7BGXxLDXAz

    Does that make more sense?

    (I removed the CSV bit as I assume you have that sorted).
    On Tuesday, May 21, 2013 8:14:29 PM UTC+1, dr...@aqwari.us wrote:

    Hello,

    I'm having a little trouble parsing XML. I'm trying to parse output from
    Dell's SOAP inventory service (see
    http://xserv.dell.com/services/assetservice.asmx?op=GetAssetInformation).
    My example program tries to pull out relevant info and print out
    CSV-formatted lines for each service agreement:

    http://play.golang.org/p/nJSBNyCaXB

    There's a number of things I'm unsure about:

    - I'm reading a sub-element of the XML. Do I have to specify its parents
    in a tag somewhere?
    - Should I specify the namespace in every element, just the containing
    elements, or at all?
    - When parsing nested XML, should I tag the field in the containing
    struct, or put an XMLname field in the substruct?

    Unfortunately I have to parse a lot of nasty XML at my job. I would love
    to be able to use Go to do it.

    Cheers,
    David
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Droyo at May 22, 2013 at 1:03 am
    Hi Phil,

    Thanks for the example, that makes sense. I took a different route, using
    an xml.Decoder to descend into the element until I found the <Asset> tag,
    and using DecodeElement from there. It would be nice to have something
    similar to the "//" shortcut in xpath (finds an element at arbitrary depth
    in the document), but that should be easy to put into a function.

    Code is at http://play.golang.org/p/AgNxTFZn4K

    Cheers,
    David
    On Tuesday, May 21, 2013 8:06:38 PM UTC-4, ph...@harris-family.info wrote:

    Hi,

    As far as I can see when parsing (unmarshalling) XML you need to describe
    the entire schema of the XML document, I've knocked up a quick example here
    using the xml data file you have in your example,
    http://play.golang.org/p/7BGXxLDXAz

    Does that make more sense?

    (I removed the CSV bit as I assume you have that sorted).
    On Tuesday, May 21, 2013 8:14:29 PM UTC+1, dr...@aqwari.us wrote:

    Hello,

    I'm having a little trouble parsing XML. I'm trying to parse output from
    Dell's SOAP inventory service (see
    http://xserv.dell.com/services/assetservice.asmx?op=GetAssetInformation).
    My example program tries to pull out relevant info and print out
    CSV-formatted lines for each service agreement:

    http://play.golang.org/p/nJSBNyCaXB

    There's a number of things I'm unsure about:

    - I'm reading a sub-element of the XML. Do I have to specify its parents
    in a tag somewhere?
    - Should I specify the namespace in every element, just the containing
    elements, or at all?
    - When parsing nested XML, should I tag the field in the containing
    struct, or put an XMLname field in the substruct?

    Unfortunately I have to parse a lot of nasty XML at my job. I would love
    to be able to use Go to do it.

    Cheers,
    David
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 21, '13 at 7:14p
activeMay 22, '13 at 1:03a
posts3
users2
websitegolang.org

2 users in discussion

Droyo: 2 posts Phil: 1 post

People

Translate

site design / logo © 2022 Grokbase