title: Selecting Nodes in XSD schema using Xpath
body: <p>I have the following code that I wish to use to select all the elements I will need in a certain sequence. Here's the snippet:</p>
  
  <pre><code>            XmlDocument schema = new XmlDocument();
              schema.Load(SchemaFileName);
              XmlNamespaceManager xnm = new XmlNamespaceManager(schema.NameTable);
              xnm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
              XmlNodeList list = schema.SelectNodes(Path);
  </code></pre>
  
  <p>However, I'm not sure what I should write as the path. Ideally I want to select all the child nodes of the "sequence" tag, but when I set the Path to "sequence", that doesn't give me anything when I run it. The nodelist is just blank. What I'm trying to do is get the names of the elements that I will need (in order) for the validation of an xml file. </p>
  
  <p>Additionally, when I set the Path as "//@name", I do get something, however, that selects all of the elements with "name" as an attribute. The ones I want are specifically right after the "sequence" tag.</p>
  
  <p>I've also tried setting the Path as "xs:sequence", but that gives me an error: "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function." Which is weird because I thought I set it up already.. </p>
  
  <p>Any help is appreciated! Thanks! If you need any more information I'll be happy to provide it.</p>
  
  <p>Sincerely,</p>
  
  <p>tf.rz</p>
  
  <p>EDIT: I am using
  Visual Studio C# 2008.
  .NET 3.5 SP1</p>
  
  <p>The basic premise is related to another question i have posted regarding the reordering of datatable columns. But to shorten the explanation. I only need to say that I just simply need the names of the elements that the xsd schema will validate (in the proper order). I have a few xsd schemas, all of which follow the same "format" and are very, very static files. Thus, I know that I can safely look for the sequence tag and get all its child nodes. While Michael mentioned how there are many ways to write a schema, the schemas that I am working with are all similar and static in those regards, so if I am able to do this, it will work 100% of the time. =)</p>