Parsing XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fabio Cannizzo

    Parsing XML

    I have an XML file based on an XSD schema.

    It represents the content of a treeview (or a menu system), where the nodes
    are always of the same few types, but can be arbitrarily nested.

    I am writing my own recursive parser to read the file, but I wonder if there
    is some method ready to use provided by the .NET which does the job!

    Thanks


  • Yunus Emre ALPÖZEN [MCAD.NET]

    #2
    Re: Parsing XML

    Surely, System.Xml namespace includes too much functionality for this.
    DataSet.ReadXML is the easiest way...

    --

    Thanks,
    Yunus Emre ALPÖZEN
    BSc, MCAD.NET

    "Fabio Cannizzo" <fcannizzo.miff t2001@london.ed u> wrote in message
    news:hs3de.2061 9$p06.16407@new sfe3-gui.ntli.net...[color=blue]
    >I have an XML file based on an XSD schema.
    >
    > It represents the content of a treeview (or a menu system), where the
    > nodes are always of the same few types, but can be arbitrarily nested.
    >
    > I am writing my own recursive parser to read the file, but I wonder if
    > there is some method ready to use provided by the .NET which does the job!
    >
    > Thanks
    >[/color]


    Comment

    • Fabio Cannizzo

      #3
      Re: Parsing XML

      If I use DataSet, then I will still have to analyse the recursive structure
      of the DataSet in order to create my Menu. Am I correct?
      Thanks,
      Fabio

      "Yunus Emre ALPÖZEN [MCAD.NET]" <yemre@msakadem ik.net> wrote in message
      news:O5jw%23bkT FHA.2908@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Surely, System.Xml namespace includes too much functionality for this.
      > DataSet.ReadXML is the easiest way...
      >
      > --
      >
      > Thanks,
      > Yunus Emre ALPÖZEN
      > BSc, MCAD.NET
      >
      > "Fabio Cannizzo" <fcannizzo.miff t2001@london.ed u> wrote in message
      > news:hs3de.2061 9$p06.16407@new sfe3-gui.ntli.net...[color=green]
      >>I have an XML file based on an XSD schema.
      >>
      >> It represents the content of a treeview (or a menu system), where the
      >> nodes are always of the same few types, but can be arbitrarily nested.
      >>
      >> I am writing my own recursive parser to read the file, but I wonder if
      >> there is some method ready to use provided by the .NET which does the
      >> job!
      >>
      >> Thanks
      >>[/color]
      >
      >[/color]


      Comment

      • John R. Chaffier

        #4
        Re: Parsing XML

        I would suggest serializing to an arraylist, then use the arraylist to
        populate your treeview. The advantage to this is that you can preserve
        the structure of your nodes and read it back without any specialized
        algorithms or parsers

        John Chaffier

        Fabio Cannizzo wrote:
        [color=blue]
        >I have an XML file based on an XSD schema.
        >
        >It represents the content of a treeview (or a menu system), where the nodes
        >are always of the same few types, but can be arbitrarily nested.
        >
        >I am writing my own recursive parser to read the file, but I wonder if there
        >is some method ready to use provided by the .NET which does the job!
        >
        >Thanks
        >
        >
        >
        >[/color]

        Comment

        • Yunus Emre ALPÖZEN [MCAD.NET]

          #5
          Re: Parsing XML

          It depends. If you design your schema as a relation table. You would use
          two(count of distinct tags) data table. Just think as a relation database.
          One entity is Orders and others is OrderDetails. Same way, Menu and Submenu.
          One table should contain main menus. Other one should contain submenu.. It
          is similar to tree implementation in a database.

          --

          Thanks,
          Yunus Emre ALPÖZEN
          BSc, MCAD.NET

          "Fabio Cannizzo" <fcannizzo.miff t2001@london.ed u> wrote in message
          news:Z_3de.2062 2$p06.14039@new sfe3-gui.ntli.net...[color=blue]
          > If I use DataSet, then I will still have to analyse the recursive
          > structure of the DataSet in order to create my Menu. Am I correct?
          > Thanks,
          > Fabio
          >
          > "Yunus Emre ALPÖZEN [MCAD.NET]" <yemre@msakadem ik.net> wrote in message
          > news:O5jw%23bkT FHA.2908@TK2MSF TNGP10.phx.gbl. ..[color=green]
          >> Surely, System.Xml namespace includes too much functionality for this.
          >> DataSet.ReadXML is the easiest way...
          >>
          >> --
          >>
          >> Thanks,
          >> Yunus Emre ALPÖZEN
          >> BSc, MCAD.NET
          >>
          >> "Fabio Cannizzo" <fcannizzo.miff t2001@london.ed u> wrote in message
          >> news:hs3de.2061 9$p06.16407@new sfe3-gui.ntli.net...[color=darkred]
          >>>I have an XML file based on an XSD schema.
          >>>
          >>> It represents the content of a treeview (or a menu system), where the
          >>> nodes are always of the same few types, but can be arbitrarily nested.
          >>>
          >>> I am writing my own recursive parser to read the file, but I wonder if
          >>> there is some method ready to use provided by the .NET which does the
          >>> job!
          >>>
          >>> Thanks
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Richard Blewett [DevelopMentor]

            #6
            Re: Parsing XML

            You thought about generating classes from the schema using XSD.EXE (part of the SDK) and then using the generated classes to deserialize the document using the XmlSerializer?

            This would give you an object graph to recurse into which should be easier.

            Regards

            Richard Blewett - DevelopMentor



            If I use DataSet, then I will still have to analyse the recursive structure
            of the DataSet in order to create my Menu. Am I correct?
            Thanks,
            Fabio

            "Yunus Emre ALP?ZEN [MCAD.NET]" <yemre@msakadem ik.net> wrote in message
            news:O5jw%23bkT FHA.2908@TK2MSF TNGP10.phx.gbl. ..[color=blue]
            > Surely, System.Xml namespace includes too much functionality for this.
            > DataSet.ReadXML is the easiest way...
            >
            > --
            >
            > Thanks,
            > Yunus Emre ALP?ZEN
            > BSc, MCAD.NET
            >
            > "Fabio Cannizzo" <fcannizzo.miff t2001@london.ed u> wrote in message
            > news:hs3de.2061 9$p06.16407@new sfe3-gui.ntli.net...[color=green]
            >>I have an XML file based on an XSD schema.
            >>
            >> It represents the content of a treeview (or a menu system), where the
            >> nodes are always of the same few types, but can be arbitrarily nested.
            >>
            >> I am writing my own recursive parser to read the file, but I wonder if
            >> there is some method ready to use provided by the .NET which does the
            >> job!
            >>
            >> Thanks
            >>[/color]
            >
            >[/color]



            [microsoft.publi c.dotnet.langua ges.csharp]

            Comment

            • Fabio Cannizzo

              #7
              Re: Parsing XML

              Thanks guys.
              Lots of good idea here.
              Regarding Array serialization in particular, I guess for each entry I would
              need to save the index in the array of the parent node, or something like
              that, correct?
              Thanks,
              Fabio

              "John R. Chaffier" <guido2@ptd.net > wrote in message
              news:OpWdnRoEvP iUQenfUSdV9g@pt d.net...[color=blue]
              >I would suggest serializing to an arraylist, then use the arraylist to
              >populate your treeview. The advantage to this is that you can preserve the
              >structure of your nodes and read it back without any specialized algorithms
              >or parsers
              >
              > John Chaffier
              >
              > Fabio Cannizzo wrote:
              >[color=green]
              >>I have an XML file based on an XSD schema.
              >>
              >>It represents the content of a treeview (or a menu system), where the
              >>nodes are always of the same few types, but can be arbitrarily nested.
              >>
              >>I am writing my own recursive parser to read the file, but I wonder if
              >>there is some method ready to use provided by the .NET which does the job!
              >>
              >>Thanks
              >>
              >>[/color][/color]


              Comment

              • Jianwei Sun

                #8
                Re: Parsing XML

                Richard Blewett [DevelopMentor] wrote:[color=blue]
                > You thought about generating classes from the schema using XSD.EXE (part of the SDK) and then using the generated classes to deserialize the document using the XmlSerializer?
                >
                > This would give you an object graph to recurse into which should be easier.
                >[/color]
                [I agree this is a good idea in most cases, but for some complicated
                schema, actually, it won't generate correct classes to handle that , and
                will report some encrypted error message which at least misleads me. ]
                [color=blue]
                > Regards
                >
                > Richard Blewett - DevelopMentor
                > http://www.dotnetconsult.co.uk/weblog
                > http://www.dotnetconsult.co.uk
                >[/color]

                [color=blue]
                > If I use DataSet, then I will still have to analyse the recursive structure
                > of the DataSet in order to create my Menu. Am I correct?
                > Thanks,
                > Fabio
                >
                > "Yunus Emre ALP?ZEN [MCAD.NET]" <yemre@msakadem ik.net> wrote in message
                > news:O5jw%23bkT FHA.2908@TK2MSF TNGP10.phx.gbl. ..[color=green]
                > > Surely, System.Xml namespace includes too much functionality for this.
                > > DataSet.ReadXML is the easiest way...
                > >
                > > --
                > >
                > > Thanks,
                > > Yunus Emre ALP?ZEN
                > > BSc, MCAD.NET
                > >
                > > "Fabio Cannizzo" <fcannizzo.miff t2001@london.ed u> wrote in message
                > > news:hs3de.2061 9$p06.16407@new sfe3-gui.ntli.net...[color=darkred]
                > >>I have an XML file based on an XSD schema.
                > >>
                > >> It represents the content of a treeview (or a menu system), where the
                > >> nodes are always of the same few types, but can be arbitrarily nested.
                > >>
                > >> I am writing my own recursive parser to read the file, but I wonder if
                > >> there is some method ready to use provided by the .NET which does the
                > >> job!
                > >>
                > >> Thanks
                > >>[/color]
                > >
                > >[/color]
                >
                >
                >
                > [microsoft.publi c.dotnet.langua ges.csharp][/color]

                Comment

                • John R. Chaffier

                  #9
                  Re: Parsing XML

                  It may be even easier than that. Lets say this is what your Xml would
                  look like

                  <xml>
                  <ArrayRoot>
                  <Node level="1">Text</Node>
                  <Node level="1">Text2 </Node>
                  <Node level="2">Text2 a</Node>
                  <Node level="2">Text2 b</Node>
                  </ArrayRoot>
                  </xml>

                  You would set up an arraylist of nodes, each node element contains the
                  text that is to be displayed in the treeview, the level attribute is
                  indicating it's depth in the tree. Now you can use a simple foreach loop
                  to traverse the arraylist to build the tree. The code would have to be
                  responsible to knowing an incoming nodes parent, so it would be
                  interesting to write using a recursive algorithm.

                  Hope this helps
                  John Chaffier

                  Fabio Cannizzo wrote:
                  [color=blue]
                  >Thanks guys.
                  >Lots of good idea here.
                  >Regarding Array serialization in particular, I guess for each entry I would
                  >need to save the index in the array of the parent node, or something like
                  >that, correct?
                  >Thanks,
                  >Fabio
                  >
                  >"John R. Chaffier" <guido2@ptd.net > wrote in message
                  >news:OpWdnRoEv PiUQenfUSdV9g@p td.net...
                  >
                  >[color=green]
                  >>I would suggest serializing to an arraylist, then use the arraylist to
                  >>populate your treeview. The advantage to this is that you can preserve the
                  >>structure of your nodes and read it back without any specialized algorithms
                  >>or parsers
                  >>
                  >>John Chaffier
                  >>
                  >>Fabio Cannizzo wrote:
                  >>
                  >>
                  >>[color=darkred]
                  >>>I have an XML file based on an XSD schema.
                  >>>
                  >>>It represents the content of a treeview (or a menu system), where the
                  >>>nodes are always of the same few types, but can be arbitrarily nested.
                  >>>
                  >>>I am writing my own recursive parser to read the file, but I wonder if
                  >>>there is some method ready to use provided by the .NET which does the job!
                  >>>
                  >>>Thanks
                  >>>
                  >>>
                  >>>
                  >>>[/color][/color]
                  >
                  >
                  >
                  >[/color]


                  Comment

                  Working...