Table of Contents

XPath

Informationen

  • Kategorien: Kernel | Klassenformeln
  • Version: 15.0.0.3282
  • Veröffentlichungsdatum: Dienstag, 15. November 2011
  • Entwickler: Schulze
  • Benötigt Datenbankänderung: Nein
  • Betreff: XPath Queries

Beschreibung

2 neue Funktionen für XPath-Abfragen:

  • XmlSelectNodeValues
  • XmlSelectNodeHandles

=> XPath Version 1.0 (mit MSXML 4.0)

Beispieldaten (siehe http://www.w3schools.com/xpath/xpath_examples.asp):

======================= Inhalt von xpath.txt:

z.B. Elementabfrage /bookstore/book/title

oder Attributabfrage /bookstore/book/@content

======================= Inhalt von content.xml:

Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 XQuery Kick Start James McGovern Per Bothner Kurt Cagle James Linn Vaidyanathan Nagarajan 2003 49.99 Learning XML Erik T. Ray 2003 39.95

Beispielcode

oncallfunction
{
	var string $sXmlFile;
	var string $sXPathFile;
	var string $sXPath;
	var string $arrNodes[];
	var int $arrHandles[];
	var string $sText;
	var string $sValue;
	var int $nHandle;
	var int $i;
	var int $bResult;
	var string $sError;

	$sXmlFile = "E:\\xmltest\\content.xml";
	$sXPathFile = "E:\\xmltest\\xpath.txt";

	$sXPath = ReadTextFile( $sXPathFile );

	XmlLoadFromFile( $sXmlFile );

	$bResult = XmlSelectNodeValues( $sXPath, $arrNodes, $sError );

	if( !$bResult )
	{
		MessageBox( $sError	);
		return;
	}

	$bResult = XmlSelectNodeHandles( $sXPath, $arrHandles, $sError );

	if( !$bResult )
	{
		MessageBox( $sError	);
		return;
	}

	$sText = 
		"XPath=" + $sXPath + "\n" +
		"Xml=" + XmlStoreToString() + "\n" +
		"XPath Nodes:\n";
	
	$i = 0;
	while ( $i < GetSize( $arrNodes ) )
	{
		$sValue = "";
		$nHandle = -1;
		if ( GetSize( $arrHandles ) > 0 )
		{
			$nHandle = $arrHandles[ $i ];
			XmlGetNodeValue( $arrHandles[ $i ], $sValue );
		}

		$sText = $sText + $arrNodes[ $i ] + 
			" Handle=" + IntToStr( $nHandle ) + 
			" ValueByHandle=" + $sValue + "\n";
		$i = $i + 1;
	}

	XmlCloseDocument();

	MessageBox( $sText );
}