473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XPath, sum and number conversion

PAF
Hi,

I'm trying to evaluate a sum expression trougth .NET 2
System.Xml.XPath.XPathNavigator object.

My code is :

Dim document As New System.Xml.XmlDocument()
document.LoadXml("<?xml
version=""1.0""?><root><a>28.7</a><a>9.18</a><a>4.32</a></root>")
Dim navigator As System.Xml.XPath.XPathNavigator =
document.CreateNavigator()
navigator.Evaluate("sum(//a)")

My XML source is :

<?xml version="1.0"?>
<root>
<a>28.7</a>
<a>9.18</a>
<a>4.32</a>
</root>

When I evaluate this expression, the result is 42.19999999996, and
should be 42.2 ... So I read some news and the W3C recommendation about
conversion to numeric values in
http://www.w3.org/TR/xpath#section-Number-Functions .

There is a function called number() that effectively convert XML string
values to numeric values. But with .NET, it raise a
System.Xml.XPath.XPathException ...

Does MS-XML implements this number function ?? Any idee ?

Thanks a lot.

Best regards, Pascal

Nov 29 '06 #1
1 5683
PAF wrote:
I'm trying to evaluate a sum expression trougth .NET 2
System.Xml.XPath.XPathNavigator object.

My code is :

Dim document As New System.Xml.XmlDocument()
document.LoadXml("<?xml
version=""1.0""?><root><a>28.7</a><a>9.18</a><a>4.32</a></root>")
Dim navigator As System.Xml.XPath.XPathNavigator =
document.CreateNavigator()
navigator.Evaluate("sum(//a)")

My XML source is :

<?xml version="1.0"?>
<root>
<a>28.7</a>
<a>9.18</a>
<a>4.32</a>
</root>

When I evaluate this expression, the result is 42.19999999996, and
should be 42.2 ...
The result is double number 42.2. 42.19999999996 is memory
representation of floating point number 42.2.
If you are interested take a look at "What Every Computer Scientist
Should Know About Floating-Point Arithmetic" at
http://docs.sun.com/source/806-3568/ncg_goldberg.html.
You probably looking into result in debugger? Try to output it instead.
So I read some news and the W3C recommendation about
conversion to numeric values in
http://www.w3.org/TR/xpath#section-Number-Functions .

There is a function called number() that effectively convert XML string
values to numeric values. But with .NET, it raise a
System.Xml.XPath.XPathException ...
1. You don't need number() function - sum() function returns number.
2. No exception,
sum = navigator.Evaluate("number(sum(//a))")
works for me, but there is no need to use number() function here.
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Nov 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Clarence | last post by:
Hi - I have a problem and here is the verbose version of what I am trying to do (better too much info than not enough). I am searching through about 4,700 XML files containing company contact...
2
by: Jesper Denmark | last post by:
I use Xpath to retrieve nodes in a document like : doc.SelectSingleNode("/properties/layer"); - however this is not very robust as I'm only query on text. What if width='0.200' instead of...
2
by: Echo 8 | last post by:
Is there a simple way of compare dates? I am trying to create a list of perishable stock in an inventory that is near or past its expiration date. I've tried telling it to compare a node's value...
1
by: Damien Goutte-Gattat | last post by:
I am using the .NET framework v2.0.40607 with Visual C# Express and I would like to create some custom XPath functions to use directly in a XSLT stylesheet. I called...
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
2
by: bruce | last post by:
morning.... i apologize up front as this is really more of an xpath question.. in my python, i'm using the xpath function to iterate/parse some html. i can do something like ...
0
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.