This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > July 2005 > How to retrieve a value as int or change a string to int?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to retrieve a value as int or change a string to int?
kfrost

2005-07-13, 7:38 pm

I'm trying to create a web counter, I'm fairly new to XML. I created a file
called counter.xml.

It looks like so.

<?xml version="1.0" encoding="utf-8" ?>
<counter>
<Page>
<Name>default</Name>
<Hit>2000</Hit>
</Page>
<counter/>

I just want to be able to retrieve the hit value and increment it by one and
write the value back to <Hit>

Here's what I've come up with so far.

Dim myDoc As New XmlDocument
Dim objPageElem As XmlElement
Dim strHit As String

myDoc.Load(Server.MapPath("counter.xml"))

objPageElem = myDoc.SelectSingleNode("//Page[Name='default']/Hit")
strHit = objPageElem.InnerXml

I get the value but as you see it's a string. I need it as an Int to
increment it and then write it back to the file.

Any input would be appreciated.
Han

2005-07-14, 4:24 am

You may want Int32 class. Something like,

string s="1";
int i=Int32.Parse(s) + 1;

--
Pohwan Han. Seoul. Have a nice day.
"kfrost" <kfrost@discussions.microsoft.com> wrote in message
news:BF3267EC-B88A-40C4-A45B-FD6DF6591486@microsoft.com...
> I'm trying to create a web counter, I'm fairly new to XML. I created a
> file
> called counter.xml.
>
> It looks like so.
>
> <?xml version="1.0" encoding="utf-8" ?>
> <counter>
> <Page>
> <Name>default</Name>
> <Hit>2000</Hit>
> </Page>
> <counter/>
>
> I just want to be able to retrieve the hit value and increment it by one
> and
> write the value back to <Hit>
>
> Here's what I've come up with so far.
>
> Dim myDoc As New XmlDocument
> Dim objPageElem As XmlElement
> Dim strHit As String
>
> myDoc.Load(Server.MapPath("counter.xml"))
>
> objPageElem =
> myDoc.SelectSingleNode("//Page[Name='default']/Hit")
> strHit = objPageElem.InnerXml
>
> I get the value but as you see it's a string. I need it as an Int to
> increment it and then write it back to the file.
>
> Any input would be appreciated.


kfrost

2005-07-14, 4:24 am

Thank Han, I'll give that a try.


"Han" wrote:

> You may want Int32 class. Something like,
>
> string s="1";
> int i=Int32.Parse(s) + 1;
>
> --
> Pohwan Han. Seoul. Have a nice day.
> "kfrost" <kfrost@discussions.microsoft.com> wrote in message
> news:BF3267EC-B88A-40C4-A45B-FD6DF6591486@microsoft.com...
>
>

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews