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

Abstract elements problem #100

Open
khamyl opened this issue Dec 9, 2020 · 1 comment
Open

Abstract elements problem #100

khamyl opened this issue Dec 9, 2020 · 1 comment

Comments

@khamyl
Copy link

khamyl commented Dec 9, 2020

Problem description

Is the editor dealing with abstract elements?

I have a quite complex XSD. I'll focus only to the problematic part of it.

The XML Schema

<?xml version="1.0" encoding="UTF-8"?>

...

<xs:schema>

...

<!-- the definition of abstract element-->
<xs:element name="model.respLike" abstract="true"/>

...

<!-- the reference to abstract element is used on several places -->
<xs:group name="model.biblPart">
    <xs:choice>
      <xs:element ref="ns1:model.respLike"/>
      <xs:element ref="ns1:model.imprintPart"/>
      <xs:element ref="ns1:series"/>
      <xs:element ref="ns1:meeting"/>
      <xs:element ref="ns1:relatedItem"/>
      <xs:element ref="ns1:edition"/>
      <xs:element ref="ns1:extent"/>
      <xs:element ref="ns1:idno"/>
    </xs:choice>
  </xs:group>

...

 <!-- element derived from abstract element and extended  -->
 <xs:element name="author" substitutionGroup="ns1:model.respLike">
   <xs:complexType>
     <xs:complexContent>
       <xs:extension base="ns1:macro.phraseSeq">
         <xs:attributeGroup ref="ns1:att.global.attributes"/>
         <xs:attributeGroup ref="ns1:att.canonical.attributes"/>
       </xs:extension>
     </xs:complexContent>
   </xs:complexType>
 </xs:element>

...
 <!--  abstract element used to define a complexType  -->
<xs:element name="titleStmt">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="ns1:title"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="ns1:model.respLike"/>
      </xs:sequence>
      <xs:attributeGroup ref="ns1:att.global.attributes"/>
    </xs:complexType>
  </xs:element>

The XML instance

...

<titleStmt>
  <title>Přemyšlování o dokonalosti křesťanské</title>
  <author>Jan Amos Komenský</author>
</titleStmt>

...

In the JSON generated by xsd2json.js script the <titleStmt> element 2. child is referring to the abstract element. As a result the renderChild() function is handling the <author> element as "without the defiition":

XMLElement.prototype.renderChild = function(childNode, recursive) {
  var elementsArray = this.objectType.elements;	
  if (elementsArray) {
    for ( var i = 0; i < elementsArray.length; i++) {
      var prefix = this.editor.xmlState.getNamespacePrefix(elementsArray[i].namespace);			
      if (prefix + elementsArray[i].localName == childNode.nodeName) {
        //console.log("With def.: ", childNode); //Khamyl
        var childElement = new XMLElement($(childNode), elementsArray[i], this.editor);
        childElement.render(this, recursive);
        this.addChildrenCount(childElement);
        return;
      }
    }
  }

  // Handle children that do not have a definition
  var childElement = new XMLUnspecifiedElement($(childNode), this.editor);
  childElement.render(this, recursive);
  this.addChildrenCount(childElement);
};

The questions are

  • Are the abstract elements supported?
  • If not, where you suggest to implment it
    • in schema generator (xsd2json.js)
    • in xml editor (xml_element.js)
@bbpennel
Copy link
Member

@khamyl
Would you be able to share the error message that you receive from the console?

There are a number of test cases and schemas in this project that include abstract elements (for example schema_sub.xsd and dc.xsd).

Type references are supposed to be applied to element definitions, for example here in the schema_processor. Similarly, abstract elements are supposed to be excluded from appearing as children of other elements here.

It may not currently be able to handle an abstract element definition being referenced as the child of another element, such as in titleStmt. I haven't tested this in a while, but based on skimming the implementation I would think that that child wouldn't show up at all, since I don't think the editor attempts to determine what subclasses of a definition inherit from an abstract reference like this.

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

No branches or pull requests

2 participants