Read-XML() question

Is possible to use Read-XML() just to read part of an XML file instead of the whole file? Say, from an XML file of transactions from all accounts, is it possible just to read in those from a certain account?
 

Stefan

Well-Known Member
No.

I had a quick try with importing an XML file with an XSL that performs a select, but the transformation is ignored.

tt.p
Code:
DEFINE TEMP-TABLE tt NO-UNDO
   FIELD id AS INT
   FIELD gl AS INT
   .


CREATE tt. ASSIGN tt.id = 1 tt.gl = 1000.
CREATE tt. ASSIGN tt.id = 2 tt.gl = 2000.
CREATE tt. ASSIGN tt.id = 3 tt.gl = 1000.
   
TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE:WRITE-XML( "file", "c:/temp/tt.xml" ).


MESSAGE "file created" VIEW-AS ALERT-BOX.


EMPTY TEMP-TABLE tt.


TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE:READ-XML( "file", "c:/temp/tt.xml", ?, ?, ?  ).


FOR EACH tt:
   DISPLAY tt.
END.

This first results in tt.xml:

Code:
<?xml version="1.0"?>
<tt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ttRow>
    <id>1</id>
    <gl>1000</gl>
  </ttRow>
  <ttRow>
    <id>2</id>
    <gl>2000</gl>
  </ttRow>
  <ttRow>
    <id>3</id>
    <gl>1000</gl>
  </ttRow>
</tt>

Based on this I created tt.filter.xsl:

Code:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
  <tt>
    <xsl:for-each select="tt/ttRow[gl='1000']">    
      <ttRow>
        <xsl:copy-of select="id"/>
        <xsl:copy-of select="gl"/>
      </ttRow>       
    </xsl:for-each>
  </tt>
</xsl:template>
</xsl:stylesheet>

And then manually added the xsl reference to tt.xml:

Code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="tt.filter.xsl"?>
<tt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ttRow>
    <id>1</id>
    <gl>1000</gl>
  </ttRow>
  <ttRow>
    <id>2</id>
    <gl>2000</gl>
  </ttRow>
  <ttRow>
    <id>3</id>
    <gl>1000</gl>
  </ttRow>
</tt>

When opening the XML in a browser you can see that the output xml is correctly filtered. However when continuing the progress code, all records are returned.

Alternatively:


  1. xslt process the xml first using your favorite third party library.
  2. use the sax-reader to import the xml and let that skip all irrelevant parts
  3. but the easiest is to simply import the lot with read-xml and then delete the temp-table records that do not meet your criteria.
 
Top