cancel
Showing results for 
Search instead for 
Did you mean: 

XSD Error while suppressing optional element with CreateIf (Test Tab)

Former Member
0 Kudos

Hi all,

I have a peculiar problem in MessageMapping while creating SQL XML document.

My target structure is like this


<root>
  *graphical Variable (gets filled by JDBC Lookup)
  <InsertStatement1>
  <InsertStatement2>
               :
               :
  <InsertStatementn>
</root>

All InsertStatement Element have occurence 0..1, which means they are optional. Depending on the value of the graphical variable, InsertStatement 2 shouldn't appear. I try to achieve this with the following "code":

graphVariable --> length --> greater --> createIf --> InsertStatement 2

0 -->

Translated into code, this means If graphVariable is greater 0 create InsertStatement Element.

If the condition is met (greater return "true"), the element is created. If greater returns false, the test environment raises this error message:

Cannot create target element /ns1:NameOf_MT/InsertStatement2. Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD

I'm sure that this error message must be completely wrong, because InsertStatement 2 is optional, so the XSD doesn't require that node. If I leave the node out from mapping, it won't appear, but without any error.

You're help is greatly appreciated.

Regards

Sven

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sven,

Check whether inside InsertStructure2, if there is any element which is mandatory.

-Supriya.

Former Member
0 Kudos

Hi,

there was a mandatory field inside, but I changed it's occurence to optional. The error still persists.

Best Regards

Sven

Answers (1)

Answers (1)

henrique_pinto
Active Contributor
0 Kudos

Hi Sven,

even if the field is optional, if you have defined a mapping rule, this rule will be executed and evaluated, no matter what is the occurrence of the target field. The occurrence of the field is evaluated later (i.e. if it is mandatory but wasn't created, mapping runtime will show an error).

So, the error occurs because mapping runtime was not able to execute the mapping rule you defined. Apparently, it has something to do with availability of the source field (graphVariable). Have you checked the context in which this field is evaluated? You might need to change the context to the root field.

Best regards,

Henrique.

Former Member
0 Kudos

Hi,

I already substituted the graphical variable with a constant. It lead to the same error.

Does the mapping runtime execute mappings for subelements, if the parent element is not created?

For example:

<InsertStatement 1> --> mapping rule says don't create

<Subelement> --> some mapping }

<Subelement> --> another mapping; UDF } are both these mappings executed?

Best Regards

Sven

henrique_pinto
Active Contributor
0 Kudos

Hi Sven,

I think they're executed anyways, just whether to show or not will vary.

You can confirm that by making a simple test including an UDF on internal tags that will just add a line to the trace:

...
AbstractTrace trace = container.getTrace();
trace.addInfo("UDF for field XPTO is executed!");
...

Best regards,

Henrique.

former_member200962
Active Contributor
0 Kudos

If the mapping for the parent node fails (validation not met and node not generated) then the mapping for its child nodes is not executed.

Former Member
0 Kudos

Hi all,

thanks for your efforts.

I solved the problem myself by creating a small UDF as follows:


if (Id[0].equals("0"))
{
      result.addSuppress();
}
else
{
      result.addValue("true");
}

The graphical variable is used as input (the min and max occurence is 1).

The node is created, if the Id isn't equal to 0 and suppressed if it is. No more xsd errors.

I suspect it has to do with the use of the graphical variable in addition with CreateIf standard function.

Best Regards

Sven