Loading XML file from within a project


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Loading XML file from within a project

  1. #1
    T O'Pry Guest

    Loading XML file from within a project


    I have a project that creates the menus dynamically using XML files that are
    loaded using the XMLTextReader object. This works fine as long as the XML
    files are external to the project.

    I would prefer this information be internal to the project, encapsulated
    within each view. I have added an XML file to the project, but have not been
    able to find a method to load that XML data into an object usable by the
    XMLTextReader.

    What method / class will create an object that I can use to accomplish this?


  2. #2
    Dave Lewis Guest

    Re: Loading XML file from within a project

    "T O'Pry" <topry@#nospam#henssler.com> wrote in message
    news:3d7a4c58$1@10.1.10.29...
    >
    > I have a project that creates the menus dynamically using XML files that

    are
    > loaded using the XMLTextReader object. This works fine as long as the XML
    > files are external to the project.
    >
    > I would prefer this information be internal to the project, encapsulated
    > within each view. I have added an XML file to the project, but have not

    been
    > able to find a method to load that XML data into an object usable by the
    > XMLTextReader.
    >
    > What method / class will create an object that I can use to accomplish

    this?

    I have just finished implementing this very same thing and what I did was:

    1) Created a resource (.resX) file for each form with file names that
    reflect the parent form (i.e. frmMain.vb would have resource file named
    frmMain.Menu.resx)
    2) Add a new value to the resource file which contains the *whole* XML file
    with the name "Menu"
    3) Use a resource manager object to retrieve the XML from the resource file
    which is then passed to the XML reading functions

    If you're still having trouble, post again and I'll see if I can dig out
    some of the code I use for it.

    --
    DHL
    Never ascribe to malice, that which can be explained by incompetence



  3. #3
    Kathleen Dollard Guest

    Re: Loading XML file from within a project

    Dave,

    > I have just finished implementing this very same thing and what I did was:
    >
    > 1) Created a resource (.resX) file for each form with file names that
    > reflect the parent form (i.e. frmMain.vb would have resource file named
    > frmMain.Menu.resx)
    > 2) Add a new value to the resource file which contains the *whole* XML

    file
    > with the name "Menu"
    > 3) Use a resource manager object to retrieve the XML from the resource

    file
    > which is then passed to the XML reading functions
    >
    > If you're still having trouble, post again and I'll see if I can dig out
    > some of the code I use for it.


    That sounds like a good idea if you want to make your XML file difficult to
    edit. If you want it to be easy to edit, You should probably place it in the
    executable directory and load it via a relative path.

    Kathleen



  4. #4
    T O'Pry Guest

    Re: Loading XML file from within a project


    >I have just finished implementing this very same thing and what I did was:
    >
    >1) Created a resource (.resX) file for each form with file names that
    >reflect the parent form (i.e. frmMain.vb would have resource file named
    >frmMain.Menu.resx)
    >2) Add a new value to the resource file which contains the *whole* XML file
    >with the name "Menu"
    >3) Use a resource manager object to retrieve the XML from the resource file
    >which is then passed to the XML reading functions
    >
    >If you're still having trouble, post again and I'll see if I can dig out
    >some of the code I use for it.
    >

    -----------------------

    Thanks for the reply.
    I have been able to do this via a resource file, which will work, but I was
    wondering if there is a method to access the XML data within an XML file
    in the project? I'm assuming there must be, otherwise what would be the point
    of creating a file of this type?

    The resource file method requires a few more steps than I would think necessary
    for something relatively straight forward. Not that this is a huge issue,
    but I would like to know how this is done so I can evaluate which option
    is best for this purpose.



  5. #5
    T O'Pry Guest

    Re: Loading XML file from within a project


    "Kathleen Dollard" <kathleen@mvps.org> wrote:
    >That sounds like a good idea if you want to make your XML file difficult
    >to edit. If you want it to be easy to edit, You should probably place it
    >in the executable directory and load it via a relative path.
    >
    >Kathleen
    >

    ----------------------------------

    Kathleen,

    Ease of editing the Menu xml is not an issue in this case. Actually, I prefer
    that it be emedded in the objects I am creating for several reasons. While
    I have this working as a resource, I would like to know how to load a XML
    file from within the project.

    Can you advise what class/method that can accomplish that?

    Regards,

    Tim


  6. #6
    Dave Lewis Guest

    Re: Loading XML file from within a project

    "T O'Pry" <topry@#nospam#henssler.com> wrote in message
    news:3d7b9ed1$1@10.1.10.29...
    >
    > >I have just finished implementing this very same thing and what I did

    was:
    > >
    > >1) Created a resource (.resX) file for each form with file names that
    > >reflect the parent form (i.e. frmMain.vb would have resource file named
    > >frmMain.Menu.resx)
    > >2) Add a new value to the resource file which contains the *whole* XML

    file
    > >with the name "Menu"
    > >3) Use a resource manager object to retrieve the XML from the resource

    file
    > >which is then passed to the XML reading functions
    > >
    > >If you're still having trouble, post again and I'll see if I can dig out
    > >some of the code I use for it.
    > >

    > -----------------------
    >
    > Thanks for the reply.
    > I have been able to do this via a resource file, which will work, but I

    was
    > wondering if there is a method to access the XML data within an XML file
    > in the project? I'm assuming there must be, otherwise what would be the

    point
    > of creating a file of this type?


    I think I see you point. You want to add an XML file to the project, set
    it's "Build Action" property to "Compile" (so that the file is part of the
    object) and then use the regular file loading methods to manipulate the XML?
    I did do a quick test to see if the file is compiled into the object (which
    it is), but I have no idea how to get the text back out again, because I
    don't have a reference to it.

    > The resource file method requires a few more steps than I would think

    necessary
    > for something relatively straight forward. Not that this is a huge issue,
    > but I would like to know how this is done so I can evaluate which option
    > is best for this purpose.


    Yes, I know what you mean. I'll continue looking and if I find anything,
    I'll come back and post it.

    --
    DHL
    Never ascribe to malice, that which can be explained by incompetence



  7. #7
    Dave Lewis Guest

    Re: Loading XML file from within a project


    "Kathleen Dollard" <kathleen@mvps.org> wrote in message
    news:3d7b454a$1@10.1.10.29...
    > Dave,
    >
    > > I have just finished implementing this very same thing and what I did

    was:
    > >
    > > 1) Created a resource (.resX) file for each form with file names that
    > > reflect the parent form (i.e. frmMain.vb would have resource file named
    > > frmMain.Menu.resx)
    > > 2) Add a new value to the resource file which contains the *whole* XML

    > file
    > > with the name "Menu"
    > > 3) Use a resource manager object to retrieve the XML from the resource

    > file
    > > which is then passed to the XML reading functions
    > >
    > > If you're still having trouble, post again and I'll see if I can dig out
    > > some of the code I use for it.

    >
    > That sounds like a good idea if you want to make your XML file difficult

    to
    > edit. If you want it to be easy to edit, You should probably place it in

    the
    > executable directory and load it via a relative path.


    Kathleen,

    Whether or not the file is difficult to edit is the lesser concern for me.
    The greater concern is not allowing an end user to tinker with the XML and
    the easiest way to do that is to embed it into the object. To edit it
    myself, I just fire up XML Spy, change whatever needs changing and then copy
    and paste the result into the resource file. Not an ideal solution I agree
    but it works.

    --
    DHL
    Never ascribe to malice, that which can be explained by incompetence



  8. #8
    Kathleen Dollard Guest

    Re: Loading XML file from within a project

    Tim,

    To work with the DOM

    Dim xmlDoc as new XML.XMLDocument
    xmlDoc.Load(filename)

    To work with fragments via a really cool internal implementation of XSLT
    use the Xml.Xpath.XPathNavigator and related classes (node iterator, etc)

    To work with a single pass forward-only, very fast, works with large files
    approach, use the XmlReader. This is SAX like if that model would be the one
    you'd choose for your particular problem, but is a pull, not a push model.

    Kathleen

    "T O'Pry" <topry@#nospam#henssler.com> wrote in message
    news:3d7b9f9f$1@10.1.10.29...
    >
    > "Kathleen Dollard" <kathleen@mvps.org> wrote:
    > >That sounds like a good idea if you want to make your XML file difficult
    > >to edit. If you want it to be easy to edit, You should probably place it
    > >in the executable directory and load it via a relative path.
    > >
    > >Kathleen
    > >

    > ----------------------------------
    >
    > Kathleen,
    >
    > Ease of editing the Menu xml is not an issue in this case. Actually, I

    prefer
    > that it be emedded in the objects I am creating for several reasons. While
    > I have this working as a resource, I would like to know how to load a XML
    > file from within the project.
    >
    > Can you advise what class/method that can accomplish that?
    >
    > Regards,
    >
    > Tim
    >




  9. #9
    Kathleen Dollard Guest

    Re: Loading XML file from within a project

    Tim,

    I think I misunderstood your question, sorry.

    Kathleen

    <topry@#nospam#henssler.com> wrote in message news:3d7b9f9f$1@10.1.10.29...
    >
    > "Kathleen Dollard" <kathleen@mvps.org> wrote:
    > >That sounds like a good idea if you want to make your XML file difficult
    > >to edit. If you want it to be easy to edit, You should probably place it
    > >in the executable directory and load it via a relative path.
    > >
    > >Kathleen
    > >

    > ----------------------------------
    >
    > Kathleen,
    >
    > Ease of editing the Menu xml is not an issue in this case. Actually, I

    prefer
    > that it be emedded in the objects I am creating for several reasons. While
    > I have this working as a resource, I would like to know how to load a XML
    > file from within the project.
    >
    > Can you advise what class/method that can accomplish that?
    >
    > Regards,
    >
    > Tim
    >




  10. #10
    T O'Pry Guest

    Re: Loading XML file from within a project


    "Kathleen Dollard" <kathleen@mvps.org> wrote:
    >Tim,
    >
    >To work with the DOM
    >
    >Dim xmlDoc as new XML.XMLDocument
    >xmlDoc.Load(filename)
    >

    ------------------------------
    That works with an external file or existing stream - but not with a file
    of type .XML within the project.

    Still haven't been able to find a way to access that object type - although
    I would think there must be one.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center