microsoft / XmlNotepad

XML Notepad provides a simple intuitive User Interface for browsing and editing XML documents.
https://microsoft.github.io/XmlNotepad/
MIT License
966 stars 206 forks source link

Saving file introduces a new line at the top of the file, breaking my xml #399

Closed namoran closed 2 weeks ago

namoran commented 2 weeks ago

The program add the line "<?xml version="1.0" encoding="utf-8" ?>" at the start of my file. I am sure that this makes it proper xml, but in my case the file I am working with breaks when adding this line. The program should not alter the file in ways the user does not know about. Please fix. or give me the option to remove this feature. I love the program otherwise. If this can't or won't be fixed, can you recommend another free program that lets you edit the xml file in a similar interface?

lovettchris commented 2 weeks ago

I'm not sure what you mean by "", perhaps you mean the XML encoding declaration <?xml version="1.0" encoding="utf-8"?> ? Or you might be talking about "byte order marks" at the beginning of the file.

These are part of the XML standard and XML notepad is ensuring your file is a valid standard XML file. XML notepad has some "Formatting options" under the "View/Options" dialog but reserves the right to output whatever is needed to your XML file, it is after all an XML "editor".

namoran commented 2 weeks ago

I'm not sure why that quotation was empty but yes it was the XML encoding state you quoted.

Thank you for looking into this so quickly!

I understand that xml should have that line. But the xml file I'm working with doesn't. And when I change it, the program that uses that file can't recognize it anymore.

Furthermore, your program replaces a notepad or notepad++ type program in my workflow, and I'm sure that's how most users see it as well, and the expectation of the user is that what I see is what I get. That line should not be hidden from the user or added in my opinion. If that line missing means it's not truly an xml file then a warning could be shown to the user at saving time.

namoran commented 2 weeks ago

I'll look in view options and see if that gives me an option that is useful in this situation.

lovettchris commented 2 weeks ago

And when I change it, the program that uses that file can't recognize it anymore.

Then the program that uses the file is non-standard with regards to XML handling and needs to be fixed. But if the program that uses it is loading the file as a string and passing that "string" to something or processing then the XML declaration can be a problem because when the file is loaded into a string it is often no longer utf-8 but instead utf-16.

If this is the case you could search replace the utf-8 in the XML declaration and replace it with utf-16.