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

Dasel don't preserve initial XML content. #175

Open
olblak opened this issue Oct 26, 2021 · 3 comments
Open

Dasel don't preserve initial XML content. #175

olblak opened this issue Oct 26, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@olblak
Copy link

olblak commented Oct 26, 2021

Discussion?
While trying to use Dasel as a Go package in a personal project updatecli, I noticed that it drops XML comments, directives, and processes.

Describe the bug
Dasel don't preserve initial XML content.

To Reproduce
The command dasel -f example.xml -p xml

.example.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This a commment -->
<name>
    <firstname tag="xx">John</firstname>
    <lastname>Doe</lastname>
</name>

.output

<name>
    <firstname tag="xx">John</firstname>
    <lastname>Doe</lastname>
</name>

.expectedOutput

<?xml version="1.0" encoding="UTF-8"?>
<!-- This a commment -->
<name>
    <firstname tag="xx">John</firstname>
    <lastname>Doe</lastname>
</name>

Another example is the command dasel put string -p xml -f example.xml .name.firstname Tom on the same example file, generated the following file:

<name>
  <firstname>Tom</firstname>
  <lastname>Doe</lastname>
</name>

Instead of:

.expectedOutput

<?xml version="1.0" encoding="UTF-8"?>
<!-- This a commment -->
<name>
    <firstname tag="xx">John</firstname>
    <lastname>Doe</lastname>
</name>

Expected behavior
I would expect Dasel to preserve all original XML instructions

Screenshots
/

Desktop (please complete the following information):

  • OS: Linux
  • Version [1.21.2]

Additional context
After looking at Dasel and mxj code base, It appears that Dasel is manipulating a mxj.Map and could instead use the mxj.MapSeq which seems to preserve everything. I am still new to the two projects so I may need some guidance to contribute to this issue. It appears that some work is needed here but I may be missing something else.

@olblak olblak added the bug Something isn't working label Oct 26, 2021
@TomWright
Copy link
Owner

That file is indeed the one that needs editing.

I have done a quick test and found that simply using mxj.NewMapXmlSeq instead of mxj.NewMapXml doesn't work.

I'll have to do a bit more reading to find out how to correctly use mxj to solve this issue. Please bear with me!

@TomWright
Copy link
Owner

It seems that when using NewMapXmlSeq the XML version and comment information are added as map nodes at the root level causing confusion.

@olblak
Copy link
Author

olblak commented Nov 9, 2021

@TomWright Thanks for looking at this, I started looking at this comment clbanning/mxj#17 (comment) but unfortunately, I run out of time so I can't help as much as I would like to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants