FAQ
Hi,

I met a problem about modification with a node in a unknown-size XML file.
e.g., I have such a XML

<root>
...
<string name="group">golang-nuts</string>
<string name="purpose">go language</string>
...
</root>

Now I want to find the node with name="porpose" and change it to 'golang'.
However I just know how to marshal or unmarshal the xml. How can i find the
node then modify it and save the new data to xml? In case I only use
standard go pkgs.

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

  • Nvcnvn at Jan 29, 2013 at 2:27 pm
    Look like you are storing a map with that XML.
    What is the struct that marshaled to the XML?

    If you use JSON that will be easy as you can marshal a Go map.

    Vào 19:07:53 UTC+7 Thứ ba, ngày 29 tháng một năm 2013, axe đã viết:
    Hi,

    I met a problem about modification with a node in a unknown-size XML file.
    e.g., I have such a XML

    <root>
    ...
    <string name="group">golang-nuts</string>
    <string name="purpose">go language</string>
    ...
    </root>

    Now I want to find the node with name="porpose" and change it to 'golang'.
    However I just know how to marshal or unmarshal the xml. How can i find the
    node then modify it and save the new data to xml? In case I only use
    standard go pkgs.
    --
    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.
  • Axe at Jan 30, 2013 at 1:36 am
    Actually I want to find a general way to handle the XML modification, don't
    care what is the style or what is in the XML.
    br

    在 2013年1月29日星期二UTC+8下午10时27分09秒,nvcnvn写道:
    Look like you are storing a map with that XML.
    What is the struct that marshaled to the XML?

    If you use JSON that will be easy as you can marshal a Go map.

    Vào 19:07:53 UTC+7 Thứ ba, ngày 29 tháng một năm 2013, axe đã viết:
    Hi,

    I met a problem about modification with a node in a unknown-size XML
    file. e.g., I have such a XML

    <root>
    ...
    <string name="group">golang-nuts</string>
    <string name="purpose">go language</string>
    ...
    </root>

    Now I want to find the node with name="porpose" and change it to
    'golang'. However I just know how to marshal or unmarshal the xml. How can
    i find the node then modify it and save the new data to xml? In case I only
    use standard go pkgs.
    --
    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.
  • James Bardin at Jan 30, 2013 at 8:33 pm

    On Tuesday, January 29, 2013 8:36:27 PM UTC-5, axe wrote:
    Actually I want to find a general way to handle the XML modification,
    don't care what is the style or what is in the XML.
    br
    Would an external library suffice?
    Here is a go wrapper of the libxml library:
    https://github.com/moovweb/gokogiri

    --
    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.
  • Robert Johnstone at Jan 30, 2013 at 9:27 pm
    There are two (incomplete) Go package for managing XML using DOM.

    - http://bitbucket.org/rj/xmldom-go/
    - http://code.google.com/p/godom/

    They may (or may not) provide the functionality you need.

    On Tuesday, 29 January 2013 07:07:53 UTC-5, axe wrote:

    Hi,

    I met a problem about modification with a node in a unknown-size XML file.
    e.g., I have such a XML

    <root>
    ...
    <string name="group">golang-nuts</string>
    <string name="purpose">go language</string>
    ...
    </root>

    Now I want to find the node with name="porpose" and change it to 'golang'.
    However I just know how to marshal or unmarshal the xml. How can i find the
    node then modify it and save the new data to xml? In case I only use
    standard go pkgs.
    --
    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.
  • Clbanning at Jan 31, 2013 at 12:29 am
    Here you can unmarshal to a map[string]interface{} value or an intermediate
    tree. You've then just got to write a marshaler.
    - https://github.com/clbanning/x2j
    On Wednesday, January 30, 2013 3:27:05 PM UTC-6, Robert Johnstone wrote:

    There are two (incomplete) Go package for managing XML using DOM.

    - http://bitbucket.org/rj/xmldom-go/
    - http://code.google.com/p/godom/

    They may (or may not) provide the functionality you need.

    On Tuesday, 29 January 2013 07:07:53 UTC-5, axe wrote:

    Hi,

    I met a problem about modification with a node in a unknown-size XML
    file. e.g., I have such a XML

    <root>
    ...
    <string name="group">golang-nuts</string>
    <string name="purpose">go language</string>
    ...
    </root>

    Now I want to find the node with name="porpose" and change it to
    'golang'. However I just know how to marshal or unmarshal the xml. How can
    i find the node then modify it and save the new data to xml? In case I only
    use standard go pkgs.
    --
    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.
  • Axe at Jan 31, 2013 at 1:58 am
    Thx all. Now I see I have to use a 3rd pkg or I have to write a pkg to
    finish it.

    在 2013年1月29日星期二UTC+8下午8时07分53秒,axe写道:
    Hi,

    I met a problem about modification with a node in a unknown-size XML file.
    e.g., I have such a XML

    <root>
    ...
    <string name="group">golang-nuts</string>
    <string name="purpose">go language</string>
    ...
    </root>

    Now I want to find the node with name="porpose" and change it to 'golang'.
    However I just know how to marshal or unmarshal the xml. How can i find the
    node then modify it and save the new data to xml? In case I only use
    standard go pkgs.
    --
    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.
  • Peter Kleiweg at Jan 31, 2013 at 4:43 pm
    Op dinsdag 29 januari 2013 13:07:53 UTC+1 schreef axe het volgende:
    Hi,

    I met a problem about modification with a node in a unknown-size XML file.
    e.g., I have such a XML

    <root>
    ...
    <string name="group">golang-nuts</string>
    <string name="purpose">go language</string>
    ...
    </root>

    Now I want to find the node with name="porpose" and change it to 'golang'.
    However I just know how to marshal or unmarshal the xml. How can i find the
    node then modify it and save the new data to xml? In case I only use
    standard go pkgs.
    You can do this with the standard packages. Something like this (not
    tested):

    xml.Unmarshal(date, &root)
    for i, str := range root.String {
    if str.Name == "purpose" {
    root.String[i].Value = "golang"
    }
    }


    --
    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
postedJan 29, '13 at 12:07p
activeJan 31, '13 at 4:43p
posts8
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase