Sign in to follow this  
ozenc

XmlTextReader

Recommended Posts

Hi, I'm trying to dynamically allocate form controls at runtime. The first step is to parse Form Designer files generated by visual studio. I didnt encounter any problems while writing the xml file (using xmltextwriter) but reading seems to be tricky.

XmlTextReader reader = new XmlTextReader("titles.xml");
reader.WhitespaceHandling = WhitespaceHandling.Significant;
reader.ReadStartElement("FormToXML");
string nsName = reader.ReadElementString("namespace");
string className = reader.ReadElementString("class");
reader.ReadStartElement("method");
reader.ReadElementString("name");
reader.ReadStartElement("statements");
reader.ReadStartElement("statement"); // exception here
"titles.xml"
<FormToXML>
  <namespace>Temas.Pack.Forms</namespace>
  <class>PackWorkerForm</class>
  <method>
    <name>InitializeComponent</name>
    <statements>
      <statement>
        <expression type>invocation</expression type>
        <caller>this</caller>
        <function>ResumeLayout</function>
        <arguments>
          <argument>
            <expression type>boolean</expression type>
            <value>False</value>
          </argument>
        </arguments>
      </statement>
    </statements>
  </method>
</FormToXML>

This is a simplified version of my xml file with only one statement but the problem is still there. (Exception: "< is unexpected token. The exptected token is '='") I think i have a problem with my xml format but i can't find the problem.

Share this post


Link to post
Share on other sites
I don't know if this is the only problem, but you can't have element names with spaces in them ("<expression type>"). Try something like expression_type.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this