Reading/Parsing Complex XML
-
hello everyone: I need to parse a complex xml file into meaningful controls. Here is what the XML file looks like:
<Controls> <group> <field name="CheckBox1" y="34.925" x="3.175" w="28" h="6"> <ui> <checkButton> <border> <css style="single"/> <fill/> </border> </checkButton> </ui> <font face="Arial"/> <padding leftInset="1" rightInset="1"/> <textAlign vAlign="middle"/> <value> <integer>0</integer> </value> <label placement="right" reserve="21"> <textAlign vAlign="middle"/> <font face="Arial"/> <value> <text>Select Check Box</text> </value> </label> </field> <field name="textBox" y="3.175" x="3.17" w="62" h="9"> <ui> <textBox> <border> <css style=""> </css> </border> <margin/> </textBox> </ui> <font face="Arial"/> <margin topInset="1" bottomInset="1" leftInset="1" rightInset="1"/> <textAlign vAlign="middle"/> <label reserve="25"> <font face="Arial"/> <textAlign vAlign="middle"/> <value> <text>textbox label</text> </value> </label> </field> </group> </Controls>
Can you help me figure out how to read this xml and come up with: TextBox txtBox = new TextBox(); txtBox.name = "txtBox"; txtBox.Location = new Point(3,3) txtBox.Size = new Size(9, 6); ... and so on .. hopefully you get the idea of what I am trying to do. I would really appreciate your help. Thanks.
-
hello everyone: I need to parse a complex xml file into meaningful controls. Here is what the XML file looks like:
<Controls> <group> <field name="CheckBox1" y="34.925" x="3.175" w="28" h="6"> <ui> <checkButton> <border> <css style="single"/> <fill/> </border> </checkButton> </ui> <font face="Arial"/> <padding leftInset="1" rightInset="1"/> <textAlign vAlign="middle"/> <value> <integer>0</integer> </value> <label placement="right" reserve="21"> <textAlign vAlign="middle"/> <font face="Arial"/> <value> <text>Select Check Box</text> </value> </label> </field> <field name="textBox" y="3.175" x="3.17" w="62" h="9"> <ui> <textBox> <border> <css style=""> </css> </border> <margin/> </textBox> </ui> <font face="Arial"/> <margin topInset="1" bottomInset="1" leftInset="1" rightInset="1"/> <textAlign vAlign="middle"/> <label reserve="25"> <font face="Arial"/> <textAlign vAlign="middle"/> <value> <text>textbox label</text> </value> </label> </field> </group> </Controls>
Can you help me figure out how to read this xml and come up with: TextBox txtBox = new TextBox(); txtBox.name = "txtBox"; txtBox.Location = new Point(3,3) txtBox.Size = new Size(9, 6); ... and so on .. hopefully you get the idea of what I am trying to do. I would really appreciate your help. Thanks.
With an XmlDocument or do you want to use XSLT to transform it into a CS file?
-
With an XmlDocument or do you want to use XSLT to transform it into a CS file?
Well not sure what approach will be the best.... so looking for advice from you guys. Also how can I use XmlDocument to accomplish what I want? I havent worked much with xml to begin with a code example will help. Thanks.
-
Well not sure what approach will be the best.... so looking for advice from you guys. Also how can I use XmlDocument to accomplish what I want? I havent worked much with xml to begin with a code example will help. Thanks.
For part of my reporting system I do something similar, but much simpler:
<Report>
<Parameters>
<Period DataType="System.String" Align="Left" Null="false" />
<StartTime DataType="System.DateTime" Align="Left" Null="false" Format="yyyy-MM-dd HH:mm" />
<EndTime DataType="System.DateTime" Align="Left" Null="false" Format="yyyy-MM-dd HH:mm" />
</Parameters>...
from this I can populate a simple WinForms dialog with appropriate controls so the user can enter values for running the report, but I don't control font or position. Reading XML with an XmlDocument is very easy -- I'll leave the research to you. :-D Once the document is read you can enumerate the group and field elements -- I'll leave the research to you. :-D With each field, you want to translate the ui element's child's name to determine which type of control to instantiate. From there, you can set the properties and add the control to the form. Where does the XML come from? Do you have control over the schema of the XML? I think I'd make it simpler if I could.
-
For part of my reporting system I do something similar, but much simpler:
<Report>
<Parameters>
<Period DataType="System.String" Align="Left" Null="false" />
<StartTime DataType="System.DateTime" Align="Left" Null="false" Format="yyyy-MM-dd HH:mm" />
<EndTime DataType="System.DateTime" Align="Left" Null="false" Format="yyyy-MM-dd HH:mm" />
</Parameters>...
from this I can populate a simple WinForms dialog with appropriate controls so the user can enter values for running the report, but I don't control font or position. Reading XML with an XmlDocument is very easy -- I'll leave the research to you. :-D Once the document is read you can enumerate the group and field elements -- I'll leave the research to you. :-D With each field, you want to translate the ui element's child's name to determine which type of control to instantiate. From there, you can set the properties and add the control to the form. Where does the XML come from? Do you have control over the schema of the XML? I think I'd make it simpler if I could.
XML is coming from a Legacy system which is pushing out xml for dynamic form generation. I understand the "read the xml and iterate through the nodes concept", however, I was wondering if there is a better/simpler way, then just looping through the nodes, like maybe using Xpath or what have you. But thanks for the help I appreciate it.