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

Validation errors should include the containing (parent) element context #242

Open
chrispitude opened this issue Dec 11, 2018 · 3 comments

Comments

@chrispitude
Copy link

chrispitude commented Dec 11, 2018

Currently, validation errors show the expected element within the current element, but not the identity of the containing element itself, forcing the user to open a text editor to determine where 'here' is based on line number and column:

test.xml:6:11: error: element "BOTTOM" not allowed here; expected the element end-tag

It would be great if the error message could include the identity of the containing element too (see 'here'):

test.xml:6:11: error: element "BOTTOM" not allowed in "TOP" here; expected the element end-tag

Our specific use case is DITA validation via the DITA-OT, but this enhancement would be widely useful.

@chrispitude
Copy link
Author

Grammar file:

<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
  <start>
    <element name="TOP">
      <element name="MID">
        <element name="BOTTOM"><text/></element>
      </element>
    </element>
  </start>
</grammar>

Test XML file:

<?xml version="1.0"?>
<TOP>
  <MID>
    <BOTTOM>this is okay</BOTTOM>
  </MID>
  <BOTTOM>oops, not allowed here</BOTTOM>
</TOP>

@chrispitude
Copy link
Author

I believe this enhancement would be in

https://github.com/relaxng/jing-trang/blob/master/mod/pattern/src/main/com/thaiopensource/relaxng/pattern/PatternMatcher.java

in the following statement:

      if (!ok)
        error(next.isNotAllowed() ? "unknown_element" : "out_of_context_element",
              errorArgQName(qName, name, context, false),
              expectedContent(context));
}

but I don’t know Java and I have no idea how to get access to the parent of the current element to pass that as an additional name argument. :(

@chrispy-snps
Copy link

Bump - does anyone know how this could be implemented?

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

No branches or pull requests

3 participants