morbac / xmltools

XML Tools plugin for Notepad++
GNU General Public License v3.0
260 stars 57 forks source link

Problem with Pretty print #79

Closed PiMaik closed 2 years ago

PiMaik commented 3 years ago

Hi,

Using version 3.1.0.1 off the plugin with version 7.9.1 (64-bit) off the N++ and geting an error I have not come across previously.

When trying to Pretty print an xml document I get an Exception. In the xml document I'm working with I have escaped the quotation marks in the namespace by adding reverse solidus character:

<ns0:Request xmlns:ns0=\"http://the/request\">hello</ns0:Request>

If you remove the escape characters the Pretty print works as should. This has worked prevously and stoped in the current version.

Thanks for great work on the plugin!

morbac commented 3 years ago

Hi,

I cannot reproduce the exception. Please can you send a full xml sample which produces the exception ?

Moreover, can you please tell me which pretty print options you're using: in Plugins > XML Tools > Options..., then in the section "Pretty pretty options" -> what formating engine and options are you using ?

Thanks

PiMaik commented 3 years ago

Hi,

Yes, sorry, I thought that I gave you a working sample,,,, <ns0:Request xmlns:ns0=\"http://the/request\"><message>hello</message></ns0:Request>

Using the the regular Pretty print (crtl+alt+shift+B) and SimpleXml.

Cheers!

morbac commented 3 years ago

Ok. Putting a \ between the = and " make your xml invalid. Both engine (SimpleXml and QuickXml) work well when this inappropriate \ is removed. PrettyPrint engines are not prepared to this special case.

The SimpleXml engine (written by @LetMeSleepAlready) generates an exception, which imho is the less worse behaviour in such a case. I let him choose if he think that a fix is required. The QuickXml does not throw an exception, but it generates unexpected result. I will try to fix it.

PiMaik commented 3 years ago

Thanks for the feedback.

Was previous version more forgiving with this? Because although it's invalid it did work up until the last version.

morbac commented 3 years ago

Because although it's invalid it did work up until the last version.

Previous version used a very slow string processing. The pretty print function has been fully rewritten in two different fast versions. I will probably add a third version which correspond to the slow previous one.

LetMeSleepAlready commented 3 years ago

Hi,

This is happening in the new parsers because in short, they are more advanced in their understanding (and thus formatting) of xml, but as a "negative" side-effect they sometimes have different behavior when parsing invalid xml. Since this xml is very invalid (try to validate it, it will fail) the behavior is at best undefined at this point.

I think a good counter question would be: why have this xml syntax in the first place?

I'll take a look at the exception, as this should only be there for debugging.

PiMaik commented 3 years ago

Hi,

Just wanted to report the problem and that it causes the error dialog and the change in behaviour.

I'm using the syntax when formatting the xml as string in order to load it in to documents, like:

xmlDoc.LoadXml("<ns0:Request xmlns:ns0=\"http://the/request\"><message>hello</message></ns0:Request>");

and you have to escape the the quotation characters.

morbac commented 3 years ago

As a temporary solution, you can still use apostroph syntaxe instead of quotes:

xmlDoc.LoadXml("<ns0:Request xmlns:ns0='http://the/request'><message>hello</message></ns0:Request>");

morbac commented 3 years ago

The pre-release 3.1.1.0 should fix the pretty print issue when using QuickXml engine.