Sample Files (XML Extractor)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - SAX2 Developer's Guide

Sample Files (XML Extractor)

To run the application you must create the following files:

  • A sample XML file, invoices.xml. This file contains the patient invoices for a fictitious doctor's office.
  • A sample XSLT style sheet file, invoice.xsl. This file is used to transform the patient invoice data, which is extracted using SAX content handling. Each set of patient data is transformed into an HTML file.
  • A GIF image file. This file contains a piece of business logo art for the fictitious medical center using this application.

Complete Code for invoices.xml

To create the sample XML file

  1. Open Notepad.
  2. Select the code for invoices.xml (below). Then copy it, and paste it in Notepad.
  3. From Notepad, save the file as invoices.xml to the same folder that will contain the XML Extractor application.

invoices.xml

<?xml version="1.0"?>
<!DOCTYPE invoices [
<!ELEMENT invoices (invoice)*>
<!ELEMENT invoice ( patient, insurance?, procedure* )>
<!ATTLIST invoice number        CDATA   #REQUIRED
                  date          CDATA   #REQUIRED>
<!ELEMENT patient ( phone | address )*>
<!ATTLIST patient       firstname   CDATA #REQUIRED
                        familyname  CDATA #REQUIRED
                        SSN         CDATA "">
<!ELEMENT insurance ( address | phone )*>
<!ATTLIST insurance     name CDATA ""
                        plannumber      CDATA ""
                        planname        CDATA "">
<!ELEMENT procedure  (#PCDATA) >
<!ATTLIST procedure     code    CDATA #REQUIRED
                        name    CDATA ""
                        cost    CDATA ""
                        insurance_estimate      CDATA  ""
                        submitted (yes|no) "yes">
<!ELEMENT phone EMPTY>
<!ATTLIST phone         type (home|work|mobile|other)   "other"
                        number  CDATA  "">
<!ELEMENT address EMPTY>
<!ATTLIST address         type (home|work|business|other)   "other"
                        company CDATA  ""
                        line1   CDATA  ""
                        line2   CDATA  ""
                        city    CDATA  ""
                        state   CDATA  ""
                        zip     CDATA  "">
]>
<invoices>
  <invoice number="25" date="February 28, 2001">
    <patient firstname="Jeff" familyname="Smith" SSN="123456789">
      <phone type="home" number="123-4567890"/>
      <phone number="321-76543321" type="work"/>
      <address type="home" line1="123 Street" city="City" state="US" zip="12345"/>
    </patient>
    <insurance name="Humongous First Medical Insurance" plannumber="12345" planname="The Client Company">
    <phone number="098-76543321"/>
    <address type="business" line1="321 Street" city="City" state="US" zip="54321"/>
    </insurance>
    <procedure code="123" name="Cleaning nose" cost="50.00" insurance_estimate="50.00"/>
    <procedure code="124" name="Tarot reading of illnesses" cost="150.00" insurance_estimate="120.00"/>
    <procedure code="125" name="Just for fun" cost="100.00" insurance_estimate="80.00"/>
  </invoice>
  <invoice number="27" date="February 28, 2001">
      <patient firstname="James" familyname="Smith" SSN="123456765">
         <phone type="home" number="123-4562245"/>
         <address type="home" line1="432 Street" city="City" state="US" zip="12343"/>
       </patient>
       <insurance name="Humongous Second Medical Insurance" plannumber="3455" planname="Another Client Company">
          <phone number="098-76543321"/>
          <address type="business" line1="344 Street" city="Some City" state="US" zip="54323"/>
       </insurance>
       <procedure code="123" name="Cleaning nose" cost="50.00" insurance_estimate="50.00"/>
       <procedure code="124" name="Tarot reading of illnesses" cost="150.00" insurance_estimate="120.00"/>
  </invoice>
  <invoice number="29" date="February 28, 2001">
    <patient firstname="Neil" familyname="Smith" SSN="123456345">
      <phone type="home" number="125-4345890"/>
      <address type="home" line1="187 Street" city="Lost City" state="US" zip="42145"/>
    </patient>
    <insurance name="Humongous Third Medical Insurance" plannumber="12345" planname="The Lost City Client Company">
      <phone number="198-76345321"/>
      <address type="business" line1="342 Street" city="Completely Lost City" state="US" zip="111111-0000"/>
    </insurance>
    <procedure code="123" name="Cleaning nose" cost="50.00" insurance_estimate="50.00"/>
    <procedure code="125" name="Maybe they wouldn't see this line..." cost="100.00" insurance_estimate="80.00"/>
  </invoice>
</invoices>

Complete Code for invoice.xsl

To create the sample XSLT file

  1. Open Notepad.
  2. Select the code for invoice.xsl (below). Then copy it, and paste it in Notepad.
  3. From Notepad, save the file as invoice.xsl to the same folder that will contain the XML Extractor application.

invoices.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<BODY bgcolor="#FFFFE0">
<TABLE border="0" width="100%"><TR><TD>
<H1>Invoice #
<xsl:value-of select="invoice/@number"/>,<BR/>
<xsl:value-of select="invoice/@date"/>
</H1>
</TD><TD align="right"><img src="sax_extractData_logo.gif"/>
</TD></TR></TABLE>

<TABLE border="0" width="100%">
  <TR valign="top">
    <TD>
      <xsl:for-each select="/invoice/patient">
            To: <xsl:value-of select="@firstname"/><xsl:text> </xsl:text>
                <xsl:value-of select="@familyname"/>
            <BR/>Account #<xsl:value-of select="@SSN"/>
            <BR/>
            <xsl:value-of select="address/@line1"/><BR/>
            <xsl:if test="address/@line2!=''">
                <xsl:value-of select="address/@line2"/><BR/>
            </xsl:if>
            <xsl:value-of select="address/@city"/>,
            <xsl:value-of select="address/@state"/>
            <xsl:value-of select="address/@zip"/><BR/>
      </xsl:for-each>
    </TD>
    <TD>
        <xsl:for-each select="/invoice/insurance">
            Insurance: <xsl:value-of select="@name"/><BR/>
            Plan name: <xsl:value-of select="@planname"/><BR/>
            Plan #<xsl:value-of select="@plannumber"/><BR/>
            <xsl:value-of select="address/@line1"/><BR/>
            <xsl:if test="address/@line2!=''">
                <xsl:value-of select="address/@line2"/><BR/>
            </xsl:if>
            <xsl:value-of select="address/@city"/>,
            <xsl:value-of select="address/@state"/>
            <xsl:value-of select="address/@zip"/><BR/>
            <xsl:value-of select="phone/@number"/><BR/>
      </xsl:for-each>
    </TD>
  </TR>
</TABLE>
<P> </P>
<TABLE border="1" width="100%">
  <TR>
    <TD width="20%">Code</TD>
    <TD width="20%">Name</TD>
    <TD width="20%">Cost</TD>
    <TD width="20%">Insurance estimate</TD>
    <TD width="20%">Submitted</TD>
  </TR>
  <xsl:for-each select="/invoice/procedure">
  <TR>
    <TD width="20%"><xsl:value-of select="@code"/></TD>
    <TD width="20%"><xsl:value-of select="@name"/></TD>
    <TD width="20%"><xsl:value-of select="@cost"/></TD>
    <TD width="20%"><xsl:value-of select="@insurance_estimate"/></TD>
    <TD width="20%"><xsl:value-of select="@submitted"/></TD>
  </TR>
  </xsl:for-each>
</TABLE>
<P> </P>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>

Creating the Logo Art File

To create the GIF logo art file

  1. Open Paint.
  2. Right-click on the image (below).

  3. Select Copy to copy the image to the Windows Clipboard.
  4. From Paint, paste the image and save it to file as sax_extractData_logo.gif. Save the image in the same folder that will contain the XML Extractor application.

See Also

Extract Data From a Large Document | Overview of the XML Extractor Application | Application Forms (XML Extractor) | MyExtractor Class (XML Extractor) | Run the Application (XML Extractor) | How the XML Extractor Application Works