Thema: Delphi Alternative zum MSXML

Einzelnen Beitrag anzeigen

MathiasSimmack
(Gast)

n/a Beiträge
 
#7

Re: Alternative zum MSXML

  Alt 18. Apr 2004, 15:14
Zitat von Chakotay1308:
Irgendwie ist mir das ganze durchaus suspekt.
Warum? Es macht immerhin einen guten Eindruck, und die Umlernphase (wenn man bisher nur mit MS-XML gearbeitet hat) ist recht kurz.

Zitat:
Aber dann eine Frage: wenn ich OmniXML verwenden würde, müsste ich dazu dann kein MS XML mitliefern?
Ich denke: Nein.

Aber hey, eins kann OmniXML noch nicht: XML-Code umwandeln. Aus dieser Datei ("links.xml")
Code:
<?xml version="1.0"?>
<?xml-stylesheet href="links.xsl" type="text/xsl"?>
<links>
  <link href="http://www.delphipraxis.net">Delphi-PRAXiS</link>
  <link href="http://www.delphi-forum.de">Delphi-Forum</link>
  <link href="http://www.csd-software.net">CSD-Software</link>
  <link href="http://www.luckie-online.de">luckie-online</link>
</links>
wird dann XSL-Stylesheet/Transform ("links.xsl")
Code:
<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="windows-1252"
  doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" indent="no"/>

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="links">
  <html>
    <head>
      <title>Links</title>
    </head>
    <body>
      <xsl:if test="count(child::*)&gt;0">
        <table border="0" width="100%" style="border:#000000 1px solid;">
          <xsl:apply-templates/>
        </table>
      </xsl:if>
    </body>
    </html>
</xsl:template>

<xsl:template match="link">
  <xsl:if test="@href!=''">
    <tr><td>
      <a>
        <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
        <xsl:attribute name="target">_blank</xsl:attribute>
        <xsl:apply-templates/>
      </a>
    </td></tr>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>
ein HTML-Dokument. Entweder via IE oder auch mit folgendem Delphi-Code (unter Benutzung des MS-XML-Parsers):
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  xsldoc,
  xmldoc : DomDocument40;
begin
  // XML-Dokument erzeugen, ...
  xmldoc := CoDomDocument40.Create;
  if(xmldoc <> nil) then
  try
    xmldoc.async := true;
    xmldoc.resolveExternals := true;
    xmldoc.preserveWhiteSpace := true;

    // ... & laden
    xmldoc.load('links.xml');

    // XSL-Stylesheet/Transform erzeugen, ...
    xsldoc := CoDomDocument40.Create;
    if(xsldoc <> nil) then
    try
      // ... & laden
      xsldoc.load('links.xsl');

      // XML-Code mit Hilfe der XSL-Datei
      // in HTML-Code transformieren
      ShowMessage(
        xmldoc.transformNode(xsldoc.documentElement)
      );
    finally
      xsldoc := nil;
    end;

  finally
    xmldoc := nil;
  end;
end;
  Mit Zitat antworten Zitat