By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,710 Members | 1,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,710 IT Pros & Developers. It's quick & easy.

Sorting XML using XMLDOM without using XSL

P: n/a
Hi,

I've had an ASP project dumped on me written in VBScript. I'm actually a
C#/ASP.NET developer and am struggling trying to find a way to sort the
result of a XPath query executed using SelectNodes?

I'd rather not rely on external XSL files if possible.

Any help gratefully received.

Ben
Dec 9 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Ben Fidge wrote:
Hi,

I've had an ASP project dumped on me written in VBScript. I'm
actually a C#/ASP.NET developer and am struggling trying to find a
way to sort the result of a XPath query executed using SelectNodes?

I'd rather not rely on external XSL files if possible.

Any help gratefully received.

Ben


Short of writing your own procedure to sort the document, an xsl
transformation is the only way. Why are you opposed to this? There are
plenty of already-written xsl examples that can easily be found via a google
search.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Dec 9 '05 #2

P: n/a
I'm not opposed to it, I just don't have the time to sit down and learn XSL.
I was kind of hoping for a quick fix so that I can lay the thing to rest.

In .Net you can apply transformations to an XPath query in situ, whcih is
what i'm used to doing, so was hoping there was a similar method with MSXML.
"Bob Barrows [MVP]" wrote:
Ben Fidge wrote:
Hi,

I've had an ASP project dumped on me written in VBScript. I'm
actually a C#/ASP.NET developer and am struggling trying to find a
way to sort the result of a XPath query executed using SelectNodes?

I'd rather not rely on external XSL files if possible.

Any help gratefully received.

Ben


Short of writing your own procedure to sort the document, an xsl
transformation is the only way. Why are you opposed to this? There are
plenty of already-written xsl examples that can easily be found via a google
search.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Dec 9 '05 #3

P: n/a
Hi Ben,
I'm not opposed to it, I just don't have the time to sit down and learn XSL. I was kind of hoping for a quick fix so that I can lay the thing to rest.
I've just been working on a similar project, and I'd say the XSL is worth
the effort. Manipulating nodes in code is horrible.
In .Net you can apply transformations to an XPath query in situ, whcih is
what i'm used to doing, so was hoping there was a similar method with

MSXML.

Can you elaborate? In MSXML you can apply a transform too, but I don't
understand what you mean by "XPath query in situ"? Can you give me a URL to
the .NET page about this and I'll have a look.

--
Gerry Hickman
SSRU SysAdmin
Dec 12 '05 #4

P: n/a
Hi Gerry,

Below is an extraction from a C#/Xml project I worked on a while ago. It
shows how XPath is used to get a list of nodes, and how the sorting done too:

XPathDocument oDocCat = new XPathDocument(FsIndexFile);
try {
XPathNavigator oNav = oDocCat.CreateNavigator();
XPathExpression oExpr =
oNav.Compile(string.Format("/images/image[category[@level1id='{0}' or
@level2id='{0}' or @level3id='{0}']]", FsCategoryID));

oExpr.AddSort("@" + FsSortField, XmlSortOrder.Ascending,
XmlCaseOrder.None, "", XmlDataType.Text);

if (oExpr != null) {
XPathNodeIterator oIterator = oNav.Select(oExpr);

while (oIterator.MoveNext()) {
oList.Add(oIterator.Current.GetAttribute("id", ""));
}
}
}
finally {
oDocCat = null;
}

I was hoping MSXML allows you to append sort information to an XPath query
ad-hoc.

Ben

"Gerry Hickman" wrote:
Hi Ben,
I'm not opposed to it, I just don't have the time to sit down and learn

XSL.
I was kind of hoping for a quick fix so that I can lay the thing to rest.


I've just been working on a similar project, and I'd say the XSL is worth
the effort. Manipulating nodes in code is horrible.
In .Net you can apply transformations to an XPath query in situ, whcih is
what i'm used to doing, so was hoping there was a similar method with

MSXML.

Can you elaborate? In MSXML you can apply a transform too, but I don't
understand what you mean by "XPath query in situ"? Can you give me a URL to
the .NET page about this and I'll have a look.

--
Gerry Hickman
SSRU SysAdmin

Dec 13 '05 #5

P: n/a
Hi Ben,

Interesting; I don't see an equivalent in MSXML; it looks like you'd
have to use an in-memory XSL sheet and then use this to transform the
in-memory DOM. In theory quite easy, but I have not actually tried it!

Ben Fidge wrote:
Hi Gerry,

Below is an extraction from a C#/Xml project I worked on a while ago. It
shows how XPath is used to get a list of nodes, and how the sorting done too:

XPathDocument oDocCat = new XPathDocument(FsIndexFile);
try {
XPathNavigator oNav = oDocCat.CreateNavigator();
XPathExpression oExpr =
oNav.Compile(string.Format("/images/image[category[@level1id='{0}' or
@level2id='{0}' or @level3id='{0}']]", FsCategoryID));

oExpr.AddSort("@" + FsSortField, XmlSortOrder.Ascending,
XmlCaseOrder.None, "", XmlDataType.Text);

if (oExpr != null) {
XPathNodeIterator oIterator = oNav.Select(oExpr);

while (oIterator.MoveNext()) {
oList.Add(oIterator.Current.GetAttribute("id", ""));
}
}
}
finally {
oDocCat = null;
}

I was hoping MSXML allows you to append sort information to an XPath query
ad-hoc.

Ben

"Gerry Hickman" wrote:
Hi Ben,
I'm not opposed to it, I just don't have the time to sit down and learn

XSL.
I was kind of hoping for a quick fix so that I can lay the thing to rest.

I've just been working on a similar project, and I'd say the XSL is worth
the effort. Manipulating nodes in code is horrible.
In .Net you can apply transformations to an XPath query in situ, whcih is
what i'm used to doing, so was hoping there was a similar method with

MSXML.

Can you elaborate? In MSXML you can apply a transform too, but I don't
understand what you mean by "XPath query in situ"? Can you give me a URL to
the .NET page about this and I'll have a look.

--
Gerry Hickman
SSRU SysAdmin

--
Gerry Hickman (London UK)
Dec 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.