Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reading/Parsing Complex XML

Reading/Parsing Complex XML

Scheduled Pinned Locked Moved C#
cssdesignxmljsonhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    student_rhr
    wrote on last edited by
    #1

    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.

    P 1 Reply Last reply
    0
    • S student_rhr

      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.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      With an XmlDocument or do you want to use XSLT to transform it into a CS file?

      S 1 Reply Last reply
      0
      • P PIEBALDconsult

        With an XmlDocument or do you want to use XSLT to transform it into a CS file?

        S Offline
        S Offline
        student_rhr
        wrote on last edited by
        #3

        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.

        P 1 Reply Last reply
        0
        • S student_rhr

          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.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • P PIEBALDconsult

            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.

            S Offline
            S Offline
            student_rhr
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups