xmltools icon indicating copy to clipboard operation
xmltools copied to clipboard

XML Validation Errors: Line Number Needed

Open KlugB opened this issue 4 years ago • 11 comments

After performing a XML validation against a XSD schema, the list of errors does not contain line numbers (error location). Thus, for very long files the error messages are practically useless.

Request: Please include line numbers in error messages.

(What would be really cool, of course, is if you could jump to the error by double click. But that might be a major feature, costly to implement, I guess.)

PS: The only other reference I could find is https://sourceforge.net/p/npp-plugins/feature-requests/178/ - but this forum seems to be dead.

KlugB avatar Jan 28 '21 11:01 KlugB

I'll add line number in alert message.

Now you can use annotations: in xmltools options dialog, change the option "Display errors as annotations" to "True" and select a annotation style (in my case, I selected the value "12"). You can use the button "Annotation preview" in options dialog to have an idea of annotation style.

When annotations are enabled, errors will be displayed inline at the correct location. Editor will also scroll automatically to make the annotation visible. Annotation is hidden when pressing ESC key. Here is an example of inline annotation:

image

Regards

morbac avatar Jan 28 '21 21:01 morbac

Thanks a lot for the quick response. While testing the annotations method I noticed I was working with an old version of XML tools where all errors were displayed in a text box.

At first I liked the annotations idea but I found out that your current solution has created several new problems for my typical use case: I get XML files with book data from many customers and if any errors are being encountered during processing I have to give the customer feedback.

The advantage of the old solution was that I could copy the errors and paste them directly into an email. Drawback: missing line numbers.

Your new implementation has the advantage that I can jump directly to the error's position, but it has several drawbacks:

  • The tool only jumps to the first error. If I want to find the next error, I have to correct the error first and then press Ctrl-Alt-Shift-M again. This is impracticable for files with many errors.
  • The annotation's error message cannot be copied to the clipboard
  • If I turn off annotations again, I am now presented with a message box that only displays the first error, which also cannot be copied to the clipboard.
  • Pressing ESC hides the annotation only with a several seconds delay
  • I tested your tool with a rather long file (8 MB, ~200.000 lines) and found out that with errors at larger line numbers, the tool jumps to a wrong position (up to 200 lines before the error). My guess is that it is being confused by the contents of <![CDATA[ ... ]]> sections in the file.

So, if I could choose, I'd prefer the old solution with all errors in a textbox (copy to clipboard option), just with line numbers added. I'd appreciate any support greatly!

See also #43

KlugB avatar Jan 29 '21 13:01 KlugB

First of all, you must activate "Multiple error messages" option in "MSXML Features" part of xmltools options since it is disabled by default.

Then, I just released the version 3.1.1.2 which restores the previous errors report dialog. In order to activate this mode, you must select "Dialog" in "Error display mode" option (which replaces the previous "Display errors as annotations" one). This should allow you to select and copy the error messages.

I'll give a look at wrong annotation positioning on long files as soon as possible.

morbac avatar Jan 30 '21 17:01 morbac

  • I installed 3.1.1.2 (manually; plugin manager does not offer most recent version)
  • set Multiple error messages = True
  • (tried annotation preview which blocks the whole dialog for several seconds and irritated me quite a bit)
  • created some errors at different positions in the file
  • saved the file with following header:

<?xml version='1.0' encoding='UTF-8'?> <ONIXMessage refname="ONIXMessage" shortname="ONIXmessage" release="2.1" xmlns="http://www.editeur.org/onix/2.1/reference" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.editeur.org/onix/2.1/reference C:\XML\XSD\ONIX_BookProduct_Release2.1_reference.xsd">

What happened:

  • on saving the file validation runs automatically and creates an annotation at first error
  • other errors create no annotations
  • tried Ctrl-Alt-Shift-M -> file dialog is displayed:

image

(note the missing example for a root element)

  • tried changing from annotation to error dialog instead
  • Ctrl-Alt-Shift-M still not working
  • triggered validation by changing and saving file -> error dialog is being displayed, but also only with first error (Multiple error messages is still set to True; thanks for the line number, btw)

So, I'm afraid there is still quite a lot of debugging to do. One additional question: Once it works, how would I jump to the next annotation, when multiple errors are present?

KlugB avatar Feb 01 '21 11:02 KlugB

Thanks for your feedback.

I cannot figure why the Ctrl+Alt+Shift+M shows you the xsd selection dialog since you added the schemaLocation in your xml. The only reason I can see would be a xml structure error. Use "Check XML syntax now" to ensure your xml is well-formed, by I suppose it is. Maybe it could help if you send a small anonymized xml+xsd example.

About multiple errors. Below is a test which shows the multiple errors is operational. This is based on xml and xsd available on msxml documentation image It would also help if you can provide a simple example I can test and see what is wrong.

Regards

morbac avatar Feb 01 '21 12:02 morbac

Yes, the XML is well-formed (otherwise I'd get an error on opening the file and the validation on opening would not work).

Here is a test file including the XSD in the folder structure used by me: ONIX xml sample.zip

The XSD can also be found here (referenced on https://www.editeur.org/15/Archived-Previous-Releases/#2.1%20Downloads)

With this file I can reproduce all errors described earlier. If you, for example, insert an error somewhere in the last entity you will see that the cursor jumps to a position a couple of lines before the actual error.

Another hint: If the file has no errors I do not get the xsd selection dialog when I press Ctrl-Alt-Shift-M. This happens only if I insert errors.

Hope this helps. This research is rather time consuming for me and I probably can not invest much more time into this, I'm afraid.

KlugB avatar Feb 01 '21 14:02 KlugB

Thanks for the sample.

I've tried to reproduce the issues you describe. I did some tests but for the moment plugin behaviour seems correct. The xsd selection dialog opens on Ctrl+Alt+Shift+M when inline schemaLocation or noNamespaceSchemaLocation cannot be found in xml. This is the case when xml has indeed none of these attributes in root, or when xmltools cannot find it due to xml encoding missmatch or structure error, which might be the case when you "insert errors". Therefore I'll add an implicit xml check before xml validation, which should avoid opening the xsd selection dialog when validation is not possible anyway.

Then, I tried to add pure validation errors in both top and bottom of the file. All annotations appear and are displayed in the correct lines, whatever EOL type or encoding I use. image

The same validation test in dialog mode: image

Now I agree that it would be a good thing to have a prev/next command to navigate through errors.

I will look further if I can experience same issues like you (wrong annotation position, missing errors report, etc.) but I'm also quite busy at this moment.

morbac avatar Feb 01 '21 19:02 morbac

The xsd selection dialog opens on Ctrl+Alt+Shift+M when inline schemaLocation or noNamespaceSchemaLocation cannot be found in xml. This is the case when xml has indeed none of these attributes in root, or when xmltools cannot find it due to xml encoding missmatch or structure error, which might be the case when you "insert errors".

Of course you're right. I mixed up XML syntax errors and XML validation errors. Sorry for the inconvenience I may have caused. I got confused when inserting a syntax error created an annotation (only one, however, even if multiple syntax errors were present).

Therefore I'll add an implicit xml check before xml validation, which should avoid opening the xsd selection dialog when validation is not possible anyway.

That is probably a good idea.

Now I agree that it would be a good thing to have a prev/next command to navigate through errors.

I think that would be very cool!

I will look further if I can experience same issues like you (wrong annotation position, missing errors report, etc.)

Re: wrong position - if you insert an error somewhere at the very bottom of my test file (syntax or validation error) you will find that the cursor jumps to a position about 12 lines in front of the annotation.

I don't want to appear greedy, but I have further requests:

  1. I'd appreciate to have an easy way to switch from annotation to dialog (other than "Plugins - XML Tools - Options... - Error Display Mode"), because often I need the error messages in the dialog as well as a possibility to navigate through the errors.
  2. Is there any way to force error messages being displayed in English? (Usually I'm communicating in English with customers) This might be a localization problem since I noticed that XML Notepad also creates German error messages for me.
  3. To check the XML syntax a keyboard shortcut (Ctrl+Alt+Shift+???) would come in handy.

KlugB avatar Feb 09 '21 12:02 KlugB

Hi, the new release 3.1.1.3 adds some new features which partially covers your needs:

  • A automatic xml syntax check is performed before xml validation call
  • The functions "First error", "Previous error", "Next error" and "Last error" have been added
  • The plugins adds some icons in toolbar (customizable with "Customize Toolbar" plugin and/or via xmltools options [section Toolbar]) which makes it easer to navigate through errors

I cannot reproduce the issue with wrong line reference. The error display switch will be added in a future version. Now, I'm not sure that xmltools can drive MSXML in order to select the errors language. I'll make some research on this, but I think this depends on the MSXML version you installed. You can add custom keyboard shortcuts by using the "Settings > Shortcut Mapper..." function in NPP menu (but the toolbar icon is maybe more simple to use now)

morbac avatar Apr 03 '21 07:04 morbac

I'm at 3.1.1.10 (updated from 3.1.1.2 where I had the same 'problem') (notepad++ v8.1.9.3 (64-bit), XMLEngine: MSXML), as I understand according to the following statement made above, the error (when using annotation) should be presented at the spot where it occurs.

When annotations are enabled, errors will be displayed inline at the correct location. Editor will also scroll automatically to make the annotation visible. Annotation is hidden when pressing ESC key. Here is an example of inline annotation:

But In all my tests the error is shown between the <?xml version...> and above the starting tag of the xml itself. not at the actual position, of course it also doesn't show any error lines.

image For my it happens with all the XML files I've tested, which are 3 specific types and always use external selected locally stored XSD files for validation.

SuperDre avatar Dec 27 '21 11:12 SuperDre

Hi,

Thanks a lot for you work.

I have used the file ONIX xml sample and created 3 errors : only the first one is shown (in the dialog box or in the annotations), even when I change the number of errors displayed in the options. Other people of my teams are encountered the same error.

My version of the plug-in is 3.1.1.6

Is that a known error ?

Regards

Totole75 avatar Oct 05 '22 10:10 Totole75