Having trouble with SelectNodes

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Ok, Im brand new at using XML and XPath and Im a bit stuck. Here is an example of my XML:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; worldGen<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; worldGenTag<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tag<span style="color:Blue; >TITLE<span style="color:Blue; </<span style="color:#A31515; tag<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; description<span style="color:Blue; >Title<span style="color:Blue; </<span style="color:#A31515; description<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; category<span style="color:Blue; >None<span style="color:Blue; </<span style="color:#A31515; category<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; argument<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; description<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; tooltip<span style="color:Blue; >This is the name of the parameter set.<span style="color:Blue; </<span style="color:#A31515; tooltip<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; textBoxControl<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; argument<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; worldGenTag<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; worldGen<span style="color:Blue; >
[/code]
Here is my code that tries to get some nodes out of it with SelectNodes:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; void ReadWorldGenXML()
{
XmlReader xReader = XmlReader.Create(<span style="color:#A31515; "ParamSchema.xsd");
XmlSchema xs = XmlSchema.Read(xReader,<span style="color:Blue; null);
xReader.Close();

<span style="color:Green; //Validating first time for line number
XmlReaderSettings settings = <span style="color:Blue; new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(xs);
settings.ValidationEventHandler += <span style="color:Blue; new ValidationEventHandler(XmlValidationHandler);

xReader = XmlReader.Create(<span style="color:#A31515; "WorldGen.xml",settings);
<span style="color:Blue; while (xReader.Read())
{
}
xReader.Close();

<span style="color:Green; //Validating second time for type identification
XmlDocument xDoc = <span style="color:Blue; new XmlDocument();
xDoc.Load(<span style="color:#A31515; "WorldGen.xml");
xDoc.Schemas.Add(xs);
xDoc.Validate(<span style="color:Blue; null);

XmlNodeList nList = xDoc.DocumentElement.SelectNodes(<span style="color:#A31515; "/worldGen");
<span style="color:Blue; int i = 2;
<span style="color:Blue; int p = i;

}

[/code]
The validation steps I am taking all work fine. If I put some bad tags in my XML the validation catches it. The resulting XDocument looks like it has what it needs to have after loading.
My problem is that no matter what I use for my XPath query, nList always = null. Im new to this, but even if I use "/*" as my query, which is supposed to return all nodes (right?) I get a null result. Not an empty list, a null result. Obviously I have some
fundamental misunderstanding of how this is supposed to happen.<br/>
<br/>


View the full article
 
Back
Top