XML-WRITE and omit-initial-values

lee.bourne

Member
Hi,

Using the code below, specifically the bit that sets lMinSchema = TRUE, why does my xml still contain <characterField/> ?

Ideally I'd like my xml to be:

<?xml version="1.0"?>
<xmlRow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xmlRowRow>
<characterField>text entry</characterField>
<integerField>1</integerField>
</xmlRowRow>
<xmlRowRow>
<integerField>2</integerField>
</xmlRowRow>
</xmlRow>

rather than:

<?xml version="1.0"?>
<xmlRow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xmlRowRow>
<characterField>text entry</characterField>
<integerField>1</integerField>
</xmlRowRow>
<xmlRowRow>
<characterField/>
<integerField>2</integerField>
</xmlRowRow>
</xmlRow>

Can anyone shed any light please?

Thanks,

Lee

DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE lFormatted AS LOGICAL NO-UNDO.
DEFINE VARIABLE cEncoding AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSchemaLocation AS CHARACTER NO-UNDO.
DEFINE VARIABLE lWriteSchema AS LOGICAL NO-UNDO.
DEFINE VARIABLE lMinSchema AS LOGICAL NO-UNDO.
DEFINE VARIABLE lRetOK AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE NO-UNDO xmlRow
FIELD characterField AS CHARACTER
FIELD integerField AS INTEGER
.

CREATE xmlRow.
ASSIGN
xmlRow.characterField = "text entry"
xmlRow.integerField = 1
.

CREATE xmlRow.
ASSIGN
xmlRow.integerField = 2
.

ASSIGN
cTargetType = "file"
cFile = "c:\temp\tt.xml"
lFormatted = TRUE
cEncoding = ?
cSchemaLocation = ?
lWriteSchema = FALSE
lMinSchema = TRUE.

lRetOK = TEMP-TABLE xmlRow:WRITE-XML(cTargetType,
cFile,
lFormatted,
cEncoding,
cSchemaLocation,
lWriteSchema,
lMinSchema).
 

Stefan

Well-Known Member
So why do you not, as the title of your post indicates, omit-initial values? min-xml-schema has bearing on the amount of information written in the schema part - which you are not writing since you have set write-schema to false.

Code:
DEFINE VARIABLE lFormatted AS LOGICAL NO-UNDO initial true.
DEFINE VARIABLE cEncoding AS CHARACTER NO-UNDO initial ?.
DEFINE VARIABLE cSchemaLocation AS CHARACTER NO-UNDO initial ?.
DEFINE VARIABLE lWriteSchema AS LOGICAL NO-UNDO.
DEFINE VARIABLE lMinSchema AS LOGICAL NO-UNDO initial true.
def var lcc as longchar.

DEFINE TEMP-TABLE xmlRow no-undo
   FIELD characterField AS CHARACTER
   FIELD integerField AS INTEGER
   .

CREATE xmlRow.
ASSIGN
   xmlRow.characterField = "text entry"
   xmlRow.integerField = 1
   .

CREATE xmlRow.
ASSIGN
   xmlRow.integerField = 2
   .

TEMP-TABLE xmlRow:WRITE-XML(
   "longchar",
   lcc,
   lFormatted,
   cEncoding,
   cSchemaLocation,
   lWriteSchema,
   true,  /* min-schema */
   ?, 
   true /* omit-initial-values */
).

message string(lcc ) view-as alert-box.

output is then:

Code:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<xmlRow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xmlRowRow>
    <characterField>text entry</characterField>
    <integerField>1</integerField>
  </xmlRowRow>
  <xmlRowRow>
    <integerField>2</integerField>
  </xmlRowRow>
</xmlRow>
---------------------------
OK  
---------------------------
 

lee.bourne

Member
very good point! my mistake entirely. purely a case of copying and pasting the example from the help file and changing the last parameter to true and not realising that they had left off the last 2 parameters meaning I was actually changing the min-schema parameter.
Can't believe how stupid I've been.
 
Top