XPath 3.0 in C# with Saxonica API

Today, I was playing with using Saxonica’s .NET API in C# (Microsoft .NET). The program below was based on the sample here: c:\Saxonica\Resources\samples\cs\ExamplesHE.cs You can download the samples from Saxonica on SourceForge in the file that starts with “Resources”. Sample C# Program <pre> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //Do an […]

PowerShell – Create a Directory (Path/Folder) If It Doesn’t Exit

Frequently in PowerShell, we need to add a directory if it doesn’t already exist. Simple Code – Check If the Directory Exists First This assumes the higher level directories exist, and you just want to add the lowest level directory: <pre> $targetFilePath = "e:\Dropbox\Audios\Album\Sinatra" if (!(Test-Path $targetFilePath))   {      New-Item -ItemType Directory -Path $targetFilePath | […]

How to put ASCII decimal/hex values in an XML file

For example, to put a pound (or hash) sign # in an XML file, you can use either of the following: ASCII decimal and Hex values in XML <pre> &#35; or &#x23; </pre> 23 in hex = 2×16+3 = 35 in decimal So the syntax is the ampersand and the hash tag followed by the […]

Error running Saxonica query.exe (content item for axis step is absent)

Query.exe is the implementation of the Saxon XQuery command/engine. It’s a command line program that I’m running from the Windows command prompt. Issue <pre> C:\XMLClass\XQuery>c:\Saxonica\bin\Query.exe -q:Flight3_Xquery.txt -o:flight3_xquery_out.xml Error on line 2 column 20 of Flight3_Xquery.txt:   XPDY0002: The context item for axis step root/descendant::FlightLeg is absent Query failed with dynamic error: The context item for axis […]

Generate a Schema from an XML File in PowerShell

While BizTalk includes an XML to XSD schema utility, we can do the same thing in C# or PowerShell (version 5.1 used in this example, but most of the work is done by .Net classes). The .NET System.Xml libraries include something interesting called the XmlSchemaInference object.  It can basically look at the XML data file, […]