TEIC / Roma-Antiqua

This repository houses the code for Roma Antiqua, the web based TEI software for generating customisations.
https://romaantiqua.tei-c.org
20 stars 7 forks source link

Problem parsing xml comment in a closed list #29

Open onbcst opened 5 years ago

onbcst commented 5 years ago

If I add (by hand) an xml comment to the values of a closed list I cannot change the the possible values any more due to the following error.

Fatal error: Uncaught Error: Call to undefined method DOMComment::getAttribute() in /var/www/tei-roma/roma/romadom.php:845 Stack trace: #0 /var/www/tei-roma/roma/romadom.php(736): romaDom->getAttributeValList('type', '', 'tei', 'att.typed', Array, NULL) #1 /var/www/tei-roma/roma/roma.php(1055): romaDom->getAttributeDefinition('type', '', 'tei', 'att.typed', Object(DOMDocument)) #2 /var/www/tei-roma/roma/roma.php(344): roma->processAddAttribute(NULL) #3 /var/www/tei-roma/startroma.php(33): roma->run() #4 {main} thrown in /var/www/tei-roma/roma/romadom.php on line 845

This can be forced with the following minimalistic example of adding two possible attribute values to @type (att.typed) and a comment afterwards.

    <classSpec ident="att.typed" type="atts" mode="change" module="tei">
     <attList>
      <attDef ident="type" mode="change">
       <valList type="closed" mode="replace">
        <valItem ident="typeA"/>
        <valItem ident="typeB"/><!-- my comment -->
       </valList>
      </attDef>
     </attList>
    </classSpec>

See tei_all(comment).zip for the complete source code.

It looks like Roma is iterating also over comment nodes and not only xml elements.

martindholmes commented 5 years ago

This could be fixed by checking that the DOMNode->nodeType is XML_ELEMENT_NODE before doing anything:

http://php.net/manual/en/class.domnode.php#domnode.props.nodetype

martindholmes commented 5 years ago

Tested and confirmed the bug using the attached file. It does not cause a problem for schema generation, just for editing attributes.

issue_29.odd.zip

peterstadler commented 5 years ago

Currently giving a workshop, so will review later. Just a quick note that DockerHub has been building that branch (see https://hub.docker.com/r/teic/roma/tags/) successfully for everyone to test :)

onbcst commented 5 years ago

The docker image worked for me. Thanks for your support. However the comment is deleted after saving the customization again to disk.

peterstadler commented 5 years ago

applied @martindholmes's fix so the initial error should be gone. Still, we'll need to fix the unwanted deletion of the comment!