Q:

C# - Get part of XML to be validated by XSD using attribute value

I need to validate column values before inserting them in table. I have written a common XSD for all tables and my XML looks like this.
<root>
  <table name="User">
    <column>UserId</column>
    <column>Name</column>
    <column>RoleId</column>
  </table>
  <table name="Role">
    <column>RoleId</column>
    <column>RoleName</column>
  </table>
</root>

And the xsd like this:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="table" maxOccurs="unbounded" minOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="column" maxOccurs="unbounded" minOccurs="1"/>
            </xs:sequence>
            <xs:attribute type="xs:string" name="name" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

But my condition is at one time I will insert in either 'User' or 'Role' table. So I need to validate only that part of the XML. Is it possible to access that part in c# using the attribute value which is my table name?

A:

I found the answer... I pass the path along with the attribute value.
 XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlString); 

            XmlNodeList xnList = xml1.SelectNodes("/root/table[@name='Role']");
            foreach (XmlNode xn in xnList)
            {
                string colName = xn["column"].InnerText;

            }

