Conditionally export fields on XML write

Posted by OctavioOlguin on 11-Nov-2017 09:25

Good day!.

I have this situation:

XML receiver, ask me to keep out certain nodes of the xml we are exchanging when they are empty.   That is, when its value in node equals "".there should not be present the node.

/* this is node
<cfdi:Receptor Nombre="XXXXX S.A. DE C.V." Rfc="XAXX010101000" UsoCFDI="G03" NumRegIdTrib="" ResidenciaFiscal="XXXXXX"/>

But there should not be NumRegIdTrib as it is empty, so 3rd party needs the node as this

<cfdi:Receptor Nombre="XXXXX S.A. DE C.V." Rfc="XAXX010101000" UsoCFDI="G03" ResidenciaFiscal="XXXXXX"/>

SO i've tested:
*/

ASSIGN
    ttReceptor.NumRegIdTrib:serialize-hidden = YES .

/* even I formed the field and .. */

FORM
   ttReceptor.NumRegIdTrib
   WITH FRAME scondindo.
ASSIGN
   ttReceptor.NumRegIdTrib:XML-NODE-TYPE IN FRAME scondindo = "HIDDEN".

In either case I get a run time error about (4052) not settable at runtime.

Any clue? 

Thanks

Jorge

Posted by Mike Fechner on 11-Nov-2017 09:31

Sorry - this one:

ASSIGN BUFFER ttReceptor:BUFFER-FIELD ("NumRegIdTrib"):serialize-hidden = YES .

Posted by onnodehaan on 11-Nov-2017 09:32

Hi,

If you create the XML with write-xml, you can set the boolean option "omit-initial-values"

WRITE-XML ( target-type

 , { file | stream | stream-handle | memptr | handle | longchar }

 [ , formatted [ , encoding [ , schema-location [ , write-xmlschema

 [ , min-xmlschema [ , write-before-image [ , omit-initial-values

 ] ] ] ] ] ] ] )

All Replies

Posted by Mike Fechner on 11-Nov-2017 09:28

Try
 
ASSIGN BUFFER ttReceptor::NumRegIdTrib:serialize-hidden = YES .

Posted by Mike Fechner on 11-Nov-2017 09:31

Sorry - this one:

ASSIGN BUFFER ttReceptor:BUFFER-FIELD ("NumRegIdTrib"):serialize-hidden = YES .

Posted by onnodehaan on 11-Nov-2017 09:32

Hi,

If you create the XML with write-xml, you can set the boolean option "omit-initial-values"

WRITE-XML ( target-type

 , { file | stream | stream-handle | memptr | handle | longchar }

 [ , formatted [ , encoding [ , schema-location [ , write-xmlschema

 [ , min-xmlschema [ , write-before-image [ , omit-initial-values

 ] ] ] ] ] ] ] )

Posted by OctavioOlguin on 11-Nov-2017 09:40

Thanks Mike and Onno..

I've try Mike's wisdom...

Just it worked until I used both filed's attributes:

ASSIGN

           BUFFER ttReceptor:BUFFER-FIELD("NumRegIdTrib"):serialize-hidden = YES

           BUFFER ttReceptor:BUFFER-FIELD("NumRegIdTrib"):XML-NODE-TYPE = "HIDDEN".

Posted by onnodehaan on 11-Nov-2017 09:51

Hi,

I think that setting those properties on a buffer-field will apply to all rows of the table. That means it will always get hidden. You wan't to hide them only when they are empty (initial value of string is empty), so I feel that using omit-initial-values would be the best way to go.

But perhaps I'm misreading your question.

Regards, Onno

Posted by OctavioOlguin on 11-Nov-2017 10:03

Thanks Onno.

Indeed, you expose a really defining point...  The field that are removed by accessing the buffer definition , will be keep out from the output no matter what.

In the case I expose, I wanted to keep out certain fields from _the header of the document_, but thinking ahead, I will face the problem you foresee, on the item rows where sometimes, some fields are to be kept out of xml....  so I guess the omit-initial-values is the way to go!!

Thanks!!!!

This thread is closed