Wondering how to explain this one...
I have a C# command line project. This project runs another program called condor_status.exe as a process and reads the process output as a stream of XML. The second line of this XML output that my program sees is:
<!DOCTYPE classads SYSTEM "classads.dtd">
I have no control over the path to this classads.dtd or any of the XML I get, but my program will bomb if it doesn't find the DTD, and in fact I would like to use the DTD. If I go and get this classads.dtd file and put it in the same directory as I am running MY program, it reads it fine and I am parsing an XPathDocument with an XPathNavigator. But if I run my program from a shortcut or an absolute path, it bombs, saying it can't find the classads.dtd in the current working dir. Setting a PATH variable or workingdir on the process does no good because it's looking for classads.dtd in the directory MY program is run from, not the process my program runs. I would like to just have classads.dtd in a known dir and tell my XmlReader to look there, regardless of where my program is executed from.
A lot of examples at Microsoft show you how to use the XmlResolver to have your XmlReader reroute its search for a .dtd that is located at some web http:// address and look for it on a local drive by overriding the GetEntity function of an XmlUrlResolver and attaching that to your XmlReader. I tried modifying an example, but it doesn't seem to even execute the GetEntity function if it is looking for something called "classads.dtd" that is already local, i.e. not listed as being at an http:// address. I can't change the XML so I can't even see if the GetEntity function would execute as planned by putting a copy of classads.dtd on a local website.
Has anyone ever done this, told an XmlResolver to look for a .dtd that is listed without any kind of path, presumably in the current directory, and force it to look in an absolute directory, like "file:///C:\Condor\bin\classads.dtd" ?
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace condor_machines
{
class Program
{
static void Main(string[] args)
{
List<string> Machines = new List<string>();
Process condor_status = new Process();
condor_status.StartInfo.UseShellExecute = false;
condor_status.StartInfo.RedirectStandardOutput = true;
condor_status.StartInfo.FileName = "C:\\Condor\\bin\\condor_status.exe";
condor_status.StartInfo.Arguments = "-xml";
condor_status.Start();
Stream stream = condor_status.StandardOutput.BaseStream;
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.DTD;
settings.ProhibitDtd = false;
XmlReader reader = XmlReader.Create(stream, settings);
XPathDocument xPathDocument = new XPathDocument(reader);
condor_status.WaitForExit();
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
string Machine = "//a[@n = \"Machine\"]";
XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(Machine);
while (xPathNodeIterator.MoveNext())
Machines.Add(xPathNodeIterator.Current.Value);
Machines = removeDuplicates(Machines);
foreach (string m in Machines)
Console.WriteLine(m);
}