Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

<oXygen/> general issues.
john_m
Posts: 32

Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

Wed Jun 14, 2017 10:49 pm

Hello,

I am working with a custom document and having issues using oxy_add.

I have created a basic document type, basicDocument.bd and the html framework to use the schema at: ${framework}/basicDocument.xsd.

The header of basicDocument.bd is

Code: Select all

<basicDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Within the schema, I have included (not imported) sub-schemas to keep things neat and organized. One of the schemas is for a section, estimatedCosts. estimatedCosts.xsd has variables that contain integer and decimal values. All values default to 0.

estimatedCosts.xsd (included in basicDocument.xsd):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xerces="http://xerces.apache.org"
   xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
   attributeFormDefault="unqualified" vc:minVersion="1.1"
   xmlns:xhtml="http://www.w3.org/1999/xhtml">
   
   <xs:include schemaLocation="sharedAttributes.xsd"/>
   
   <xs:element name="estimatedCost">
      <xs:complexType>
         <xs:attribute name="itemCost1" type="xs:decimal" default="0"/>
         <xs:attribute name="itemCost2" type="xs:decimal" default="0"/>
         <xs:attribute name="itemQuantity1" type="xs:integer" default="0"/>
         <xs:attribute name="itemQuantity1" type="xs:integer" default="0"/>
      </xs:complexType>
   </xs:element>   
</xs:schema>

(I realize that it may have been better to make the item costs and quantities elements instead of attributes - but that will be for a later update).

A basicDocument looks something like:

Code: Select all

<basicDocument>
   <...>
      <estimatedCosts itemCost1="0" itemCost2="0" itemQuantity1="0" itemQuantity2="0" />
   </...>
</basicDocument>

(itemCost1, itemCost2, itemQuantity1 and itemQuantity2 can be updated- but were set to 0 by default because oxy_add did not work properly when there was no default value).

When I use hard-coded numbers, oxy_add(10,5, 'number'), the function works perfectly.

When I use variables, oxy_add(attr(itemCost1), attr(itemCost2), 'number'), the function does not work - and only blank spaces are output. (I also only ever attempt to add attributes of the same type).

If I add an xsi:noNamespaceSchemaLocation to basicDocument.bd:

Code: Select all

<basicDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../basicDocument.xsd">

I can use variables without an issue.

I have verified that all of my schema and sub-schema files have identical header information - so I am confused as to why everything works except this one section - unless I add the noNamespaceSchemaLocation... especially because the noNamespaceSchemaLocation points to the same schema as the framework.

Is there a way to omit the noNamespaceSchemaLocation declaration from basicDocument.bd and have everything handled through the framework?

Any assistance would be appreciated!

Thanks!
cristi_talau
Posts: 125

Re: Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

Thu Jun 15, 2017 9:15 am

Hello,

I tried to reproduce your problem with the following sample:

https://gist.github.com/ctalau/022b86a0 ... dda4e24270

The result can be viewed here:

https://www.oxygenxml.com/webapp-demo-a ... xy_add.xml

The attribute values are properly added in my sample.

It would help if you could provide a more specific sample on which the problem manifests.

Best,
Cristian
john_m
Posts: 32

Re: Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

Mon Jun 19, 2017 9:35 pm

Hi Christian,

Thank you for your response.

I have done more troubleshooting and I believe I have isolated the issue. I forgot to include my css in my last post - so I am including it now.

Code: Select all

estimatedCost{
   
    content:
    oxy_label(text, "Cost of Item 1: ", width, 20%)
    oxy_textfield(edit, "@itemCost1", width, 15%)
    oxy_label(text, " ", width, 5%)
    oxy_label(text, "Cost of Item 2: ", width, 20%)
    oxy_textfield(edit, "@itemCost2", width, 15%)"\A\A"
   
    oxy_label(text, "Quantity of Item 1: ", width, 20%)
    oxy_textfield(edit, "@itemQuantity1", width, 15%)
    oxy_label(text, " ", width, 5%)
    oxy_label(text, "Qauntity of Item 2: ", width, 20%)
    oxy_textfield(edit, "@itemQuantity2", width, 15%)"\A\A"
   
    oxy_label(text, "Cost of Item 1 + Cost of Item 2: ")
    oxy_add(attr(itemCost1), attr(itemCost2), 'number')"\A\A"
    ...

Per my previous post, the attribute values for itemCost1, itemCost2, itemQuantity1 and itemQuantity2 are set to 0 in the schema.

I have determined that as long as there are values for the attributes (even 0), the section displays properly - the labels are displayed and the math functions work.

Code: Select all

  <estimatedCosts itemCost1="0" itemCost2="0" itemQuantity1="0" itemQuantity2="0" />
However, this does not take into account the case where a user deletes all the values. If the values are deleted, the display on the screen shows the values going back to zero. However, on save and refresh, the element has been updated to have no values for the attributes at all.

Code: Select all

  <estimatedCosts />
Maybe a better question would be - is there a way to force those values to default back to zero if the user deletes them?

I have tried setting the attributes to required - however, because they have a default value, I cannot also set the attributes to be required.

Any assistance would be greatly appreciated!

Thank you!
John
mihaela
Posts: 174

Re: Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

Tue Jun 20, 2017 10:35 am

Hi John,

The only problem that I see in your samples is that there is a difference between the name of the element used in the xml and the one declared in your schema (and css): estimatedCosts vs estimatedCost.
If I change your sample schema to use estimatedCosts element name everithing works as you expect: the default values are displayed even if the attributes are removed from the element.

Please let us know if this solves your problem or if you need further assistance.

Best Regards,
Mihaela
Mihaela Calotescu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
john_m
Posts: 32

Re: Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

Thu Jun 22, 2017 10:41 pm

Hello Mihaela,

Thank you for your response. I was trying to simplify the code (we are building a complex document) and there was a typo in the code I posted to the forum. The names match exactly in the code I've written for the project.

I'm afraid I'm not describing the situation very well, so I have created a YouTube video to demonstrate the issue: https://www.youtube.com/watch?v=6w1tz0L ... e=youtu.be

I start in xml view and you will notice that when the video starts (default) the element has attributes with the default value of 0 or 0.0.

Code: Select all

<estimatedModCost attributeVal01="0" attributeVal02="0" attributeVal03="0" ... />
I switch to author view and move from field to field, deleting the attribute values. You will notice that on the display, they fields get the default values of 0 or 0.0. However, upon viewing the XML again you will notice that the element has no attributes.

Code: Select all

<estimatedModCost />
Switching back to the author view, everything looks OK. However, upon refreshing the document, the section will no longer display (it is just a big white area).

Please let me know if this helps describe the issue better - and if there is a way to ensure that those attribute values always have the default value of 0 or a number.

Thanks!
John
mihaela
Posts: 174

Re: Issues Using oxy_add With Attribute Values Without Declaring A noNamespaceSchemaLocation

Fri Jun 23, 2017 9:47 am

Hi John,

Thank you for the video and the detailed explanation.
In the last part of the video, after refreshing the document, the "Service Bulletin" toolbar does not appear anymore. This means that the framework is not loaded, so your schema is not associated anymore with the document (this is why your empty elements are not rendered in editor).

Do you use the default refresh action (F5)? Can you please send us your framework and a small sample on our support email address (support@oxygenxml.com) to help us reproduce this sittuation?

Best Regards,
Mihaela
Mihaela Calotescu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “Other Issues”

Who is online

Users browsing this forum: No registered users and 1 guest