Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hierarchy of xml elements from yaml structure #95

Closed
sradi opened this issue Dec 3, 2016 · 6 comments
Closed

Add hierarchy of xml elements from yaml structure #95

sradi opened this issue Dec 3, 2016 · 6 comments
Labels

Comments

@sradi
Copy link

sradi commented Dec 3, 2016

Hi,

I am currently trying out ansible-xml. There's one thing, I couldn't get working:
I am referencing a variable from a yml file, which contains a list of items, that are added as xml elements to my target file. That's easy... Now I would like to reference a variable, which contains a list, where each item again contains a list. I expected, that I could add two levels of nested xml elements at once, this way. Unfortunately I am receiving this error:
TypeError: Argument must be bytes or unicode, got 'list'

Is there any way to add a full xml structure at once, with add_children?

Thanks a lot in advance!!
Stefan

@dagwieers
Copy link
Collaborator

dagwieers commented May 10, 2017

Look at the example at #101, the same technique is possible for adding multiple levels.

Using the YAML input type:

  - xml:
      file: /tmp/test156.new.xml
      xpath: /List
      pretty_print: yes
      add_children:
        - Item:
            _Id: id002
            _:
              - Label:
                  _:
                    - Name: Demo 2
                    - Source: Vinyl
              - Active: "0"

Using the XML input type:

  - xml:
      file: /tmp/test156.new.xml
      xpath: /List
      input_type: xml
      pretty_print: yes
      add_children:
        - "<Item id='id002'><Label><Name>Demo 2</Name><Source>Vinyl</Source></Label><Active>0</Active></Item>"

If you're happy with these examples, please close this issue :-)

@dagwieers
Copy link
Collaborator

@sradi Please provide feedback and/or close this issue.

@sradi
Copy link
Author

sradi commented Jun 13, 2017

Thanks for the help. That looks helpful! :)

@sradi sradi closed this as completed Jun 13, 2017
@UnitedMarsupials-zz
Copy link

UnitedMarsupials-zz commented Jan 4, 2019

@dagwieers' examples are wonderful -- and did help me finish my project -- but why is not there anything of the kind in the xml-module's official documentation? All of the examples there show merely, how to set individual values...

Update: Changed link above to latest development docs

@dagwieers
Copy link
Collaborator

@UnitedMarsupials I think we didn't add all examples from the integration tests because there would be too many examples in the module's documentation. But maybe we should add a section in the Ansible documentation related to the xml module functionality ?

If you think this is something you'd like to contribute, let me know.

@dagwieers
Copy link
Collaborator

I added a TODO item on the community wiki with links to the original README and the integration tests: https://github.com/ansible/community/wiki/Module:-xml#todo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants