eZ Community » Forums » eZ Publish 5 Platform » Validating XMLText custom tags
expandshrink

Validating XMLText custom tags

Validating XMLText custom tags

Tuesday 22 September 2015 1:13:57 pm - 3 replies

I'm trying to load XMLText in the new stack. The XML contains a custom tag:

 <?xml version='1.0' encoding='utf-8'?><section><paragraph><custom name="quote" align="center" author="Myself">Lorem ipsum.</custom></paragraph></section>

When I add this content to an ezxmltext field with:

        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();
        $contentUpdateStruct->setField( $fieldIdentifier, $content );

I get the following error message:

 [eZ\Publish\Core\Base\Exceptions\InvalidArgumentException]
  Argument 'xmlString' is invalid: Validation of XML content failed: Element
  'custom', attribute 'author': The attribute 'author' is not allowed.

As a workaround I can edit vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/XmlText/Input/Resources/schemas/ezxml.xsd and add the line:

 <xs:attribute name="author" type="xs:string"/>

to the definition for 'custom', but that is not a satisfactory solution.

How can I override or extend the validation schema or otherwise correctly load custom tags through the API? It works fine using the legacy interface.

I'm using eZ Publish version 2014.11.

Thanks!

Andy

Modified on Tuesday 22 September 2015 1:15:57 pm by Andy Caiger

Wednesday 23 September 2015 7:10:59 pm

Hi Andy,

I think you will need to have a custom XSL sheet registered in the kernel which will be used to validate your custom tag. See here for an example:

https://doc.ez.no/display/EZP/How...t+a+Custom+Tag+for+XMLText+FieldType

Thursday 24 September 2015 12:30:34 pm

Hi Edi
Thanks very much for your reply.
We're familiar with rendering custom tags in the new stack, following the cookbook example as you suggested. But my problem is related to validating custom tags through the API not rendering them. I have registered an XSL stylesheet for my custom tag and it renders fine in the new stack frontend if I create the content using the legacy Online Editor. But if I try to create the content using the API (on the command line) I get the validation error message above.

The relevant section of ezxml.xsd is:

<xs:complexType name="custom" mixed="true">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:group ref="commonInlineElements"/>
      <xs:group ref="blockElements"/>
    </xs:choice>
    <xs:attributeGroup ref="align"/>
    <xs:attribute name="name" use="required" type="xs:string"/>
    <xs:anyAttribute namespace="http://ez.no/namespaces/ezpublish3/custom/" processContents="skip"/>
  </xs:complexType>

It seems that the xs:anyAttribute tag isn't working. If I delete its namespace attribute then it works:

 <xs:anyAttribute processContents="skip"/>

But modifying a file in vendors is not a good long-term solution. What's the correct way for dealing with this?

Thanks!

Andy

Tuesday 31 January 2017 12:12:05 am

I got the same issue, but when using the preview module from admin legacy, frontend works fine for an accordion custom tag, but in the admin preview it fails, example mysite.com/admin/content/versionview/<id>/<version>/eng-US/site_access/<sa> the custom tags does not work, it shows the xml block raw content, instead of the html5 converted markup.

<custom xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/" name="accordion" custom:identifier="Lorem Ipsum Identifier"><custom name="accordion-item" custom:title="Audience Response Lorem Ipsum"><p>Accordion Contente text <strong>ITEM 1</strong>: Lorem ipsum xxxx</p></custom><custom name="accordion-item" custom:title="Questions Writing Information"><a name="eztoc_1_1_1_1_1_1_1" id="eztoc_1_1_1_1_1_1_1"></a><h7>Accordion Content <strong>ITEM 2</strong>: Lorem ipsum xxxx</h7></custom></custom>

Modified on Tuesday 31 January 2017 12:13:22 am by Diego Amaya

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from