Dataset to XML - how to exclude the root element?

Posted by temeq on 25-Oct-2010 02:41

I have a dataset defined:

DEFINE DATASET dsAllResults FOR ttTestSuite, ttTestCase, ttFailure 
    DATA-RELATION fTestSuite FOR ttTestSuite,    
    ttTestCase RELATION-FIELDS(fSuiteNumber, fSuiteNumber) NESTED
    DATA-RELATION fTestCase FOR ttTestCase,    
    ttFailure RELATION-FIELDS(fTestCaseNumber, fTestCaseNumber) NESTED.


And I manage to write it to XML:

ASSIGN 
         cTargetType     = "file" 
         cFile           = iResultXmlFile
         lFormatted      = TRUE 
         cEncoding       = "UTF-8"
         cSchemaLocation = ?
         lWriteSchema    = FALSE 
         lMinSchema      = TRUE
         lBeforeTable    = FALSE
        .

lRetOK = DATASET dsAllResults:WRITE-XML(cTargetType, cFile, lFormatted, cEncoding,  cSchemaLocation, lWriteSchema, lMinSchema, lBeforeTable).

But the problem is that the result file looks like this:


<?xml version="1.0" ?>
<dsAllResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <testsuite>
    <testcase>
    </testcase>

    <testcase>
     </testcase>
  </testsuite>
  <testsuite>
     <testcase>
     </testcase>   

    <testcase>
     </testcase>
  </testsuite>
</dsAllResults>

And I would need it to look like this (without the dsAllResults root element):

<?xml version="1.0" ?>

  <testsuite>
     <testcase>
     </testcase>

    <testcase>
     </testcase>
  </testsuite>
  <testsuite>
     <testcase>
     </testcase>   

    <testcase>

     </testcase>

   </testsuite>

Is there any way how to do this with Dataset+Write-xml or do I need to use some other methods?

All Replies

Posted by mresnick on 25-Oct-2010 07:56

Temeq,

What you are trying to do is not well-formed XML. Well-formed XML must have a single root element. If you try to parse the XML you wish to generate, the result will be a parsing error when the XML parse encounters the testsuite element.

Michael

Posted by temeq on 25-Oct-2010 08:25

Thank you Michael for helping to open my eyes!

OK, now I need to figure out how to loop through the dataset (I am a total newbie) and write each of those testsuite-elements to a separate file.

Any advise on this one?

Posted by mresnick on 25-Oct-2010 08:30

Temeq,

You can use WRITE-XML( ) on each of the tables in the same way you wanted to use it on the Dataset as a whole.

Michael

This thread is closed