Reading Specific Parts of an XML Document

  • Thread starter Thread starter Jordan
  • Start date Start date
J

Jordan

I'm using an xml document as the source for my site's navigation. I have it
working but am curious if I've chosen the best method (performance wise) of
reading this xml document. Becuase this xml file has my site's complete
navigation, I need to "jump around" in it to get to the data I need based on
the page. I'm using the Skip() method of the XmlReader class to do this.

Is this the best way to move forward in an xml document?

I also have another question too now that I'm thinking about it - what would
be the best way to cache my navigation as it won't change often at all?

tia, j
 
Consider adding the metadata for navigation, if not there already, as nodes.
Then, you can use XPath to prune out the nodes you want. For example:

<SideMenu>
<LinkName>Policies</LinkName>
<LinkURL>policies.aspx</LinkURL>
<Section>Home</Section>
</SideMenu>

NOTE: The XML here is DataSet style, but the principle is still the same.

With XPATH, you can set up a query that only finds those side menu items
that are in section Home. The reason I use DataSet XML for menus is we are
aiming for eventually moving the menus to a database, with an admin utility
for all of our applications. By starting with XML that is DataSet oriented,
I can easily change to the database, when finished, without rewriting the
bind.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Answering both question in one:

If the navigation file is global to all users, store it as an Application[]
variable or -to avoid serialization - as a static/shared property of a
class.
In any case, if the navigation xml is cached you may keep it as an
XmlDocument object, and use the XPath query syntax for a fast search.

Going a little further, you may encapsulate the navigation logic as
static/shared members of a class (which also holds the xml as a static
private property). That way the navigation file access would be contained
within that class and would be easily changed with no impact on the
application

Regards
Jose.
 
Ok - I haven't found in asp.net that you can use XPath syntax when using
something like
new xmlReader(MyXmlFile). I know there's an XQuery component that I can
download, but I was hoping to stay away from another component at this time.

right now, my xml file is not DataSet style. Here's a snippet
<navigation>

<node area="Courses" root="/courses">

<page url="/courses" headeronly="false" display="expand">Browse Courses

<subpage url="/courses/browsebysubject.asp">by Subject</subpage>

<subpage url="/courses/browsebynumber.asp">by Course Number</subpage>

</page>

<page url="/courses/index.asp">Course Index</page>

<page url="/courses/basics.asp">Course Basics</page>

</node>

<node> .... </node>

What I'm doing is just using the While (xmlReader.Read()) and going through
it on my own, not using any specific DataBind to a control, but I am using:

MyDiv.InnerHtml = MyCustomStringBuilderFromMyWhileLoop.ToString();

Is your method better (have an article maybe)??
 
Jose,

Do you mean I can do something like this?

Application["MyXmlFile"] = new xmlReader(MyXmlFile);

My reply to "Cowboy" earlier said that I didn't know you could use XPath in
..NET exactly, but use XQuery for example. Seems like I'm wrong about this.
Going a little further, you may encapsulate the navigation logic as
static/shared members of a class (which also holds the xml as a static
private property). That way the navigation file access would be contained
within that class and would be easily changed with no impact on the
application

This is kinda what I was trying to accomplish. I was going to compile my
nav.dll and in my pages, just have my <div id="myNav"> and use
MyVav.InnerHtml = MyDLLsCustomHTMLString. That way, I can change the XmlDoc
and have my navigation change w/o impacting the application too.


Jose Marcenaro said:
Answering both question in one:

If the navigation file is global to all users, store it as an Application[]
variable or -to avoid serialization - as a static/shared property of a
class.
In any case, if the navigation xml is cached you may keep it as an
XmlDocument object, and use the XPath query syntax for a fast search.

Going a little further, you may encapsulate the navigation logic as
static/shared members of a class (which also holds the xml as a static
private property). That way the navigation file access would be contained
within that class and would be easily changed with no impact on the
application

Regards
Jose.

Jordan said:
I'm using an xml document as the source for my site's navigation. I have it
working but am curious if I've chosen the best method (performance wise) of
reading this xml document. Becuase this xml file has my site's complete
navigation, I need to "jump around" in it to get to the data I need
based
on
the page. I'm using the Skip() method of the XmlReader class to do this.

Is this the best way to move forward in an xml document?

I also have another question too now that I'm thinking about it - what would
be the best way to cache my navigation as it won't change often at all?

tia, j
 
Jordan,
Do you mean I can do something like this?
Application["MyXmlFile"] = new xmlReader(MyXmlFile);

I didn't think of keeping an open reader; I actually meant something like
xmlDoc = new XmlDocument();
xmlDoc.load( MyXmlFile);
Application["MyXmlDoc"] = xmlDoc;
or rather
MyNavigationClass.XmlDoc = xmlDoc; // static member

You could also use the Cache object, which also allows for refreshing the
data when needed

Hope this helps
Jose.

Jordan said:
Jose,

Do you mean I can do something like this?

Application["MyXmlFile"] = new xmlReader(MyXmlFile);

My reply to "Cowboy" earlier said that I didn't know you could use XPath in
.NET exactly, but use XQuery for example. Seems like I'm wrong about this.
Going a little further, you may encapsulate the navigation logic as
static/shared members of a class (which also holds the xml as a static
private property). That way the navigation file access would be contained
within that class and would be easily changed with no impact on the
application

This is kinda what I was trying to accomplish. I was going to compile my
nav.dll and in my pages, just have my <div id="myNav"> and use
MyVav.InnerHtml = MyDLLsCustomHTMLString. That way, I can change the XmlDoc
and have my navigation change w/o impacting the application too.


Jose Marcenaro said:
Answering both question in one:

If the navigation file is global to all users, store it as an Application[]
variable or -to avoid serialization - as a static/shared property of a
class.
In any case, if the navigation xml is cached you may keep it as an
XmlDocument object, and use the XPath query syntax for a fast search.

Going a little further, you may encapsulate the navigation logic as
static/shared members of a class (which also holds the xml as a static
private property). That way the navigation file access would be contained
within that class and would be easily changed with no impact on the
application

Regards
Jose.

Jordan said:
I'm using an xml document as the source for my site's navigation. I
have
it
working but am curious if I've chosen the best method (performance
wise)
of
reading this xml document. Becuase this xml file has my site's complete
navigation, I need to "jump around" in it to get to the data I need
based
on
the page. I'm using the Skip() method of the XmlReader class to do this.

Is this the best way to move forward in an xml document?

I also have another question too now that I'm thinking about it - what would
be the best way to cache my navigation as it won't change often at all?

tia, j
 
Back
Top