473,396 Members | 1,853 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,396 software developers and data experts.

force evaluation on string or character

Hi,
I am working with DOM and I need to do the following:

<sequence>
<element name="input1" type="string"/>
<element name="input2" type="string"/>
<element name="input3" type="string"/>
</sequence>
The problem is, I do not know how many inputs I will have until runtime. So
I have to generate the element Elements on the fly. One way to construct the
node would be like this:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<sequence>" +
"<element name='input1' type='string'/>" +
....and so on... +
"</seqence>");
MyDoc.ReplaceChild( doc, MyDoc.FirstChild ); or something along those lines

My question is, since I do not have a way of knowing how many inputs we have
until runtime, I have to put a for loop and name the inputs as input1,
input2....

How can I ge this 'input1' from my code which is doing this
for (int i = 0; i < numOfOperations; i++)
s = s + "<element name="+ 'input + i '+" type='string'/>");

I am getting 'input+i' instead of input1. Is there any way to force the
character to
convert the value instead of treating it as a literal??

Thanks
Faraz
Nov 16 '05 #1
2 1752
Hi Faraz

You probably don't want to create your xml this way. Look at using
CreateElement and AppendChild instead...your way gives problems in terms of
hard to read string concatenation (as you have found!)...

s = s + "<element name="'input" + i + "' type='string'/>" should work
better...

HTH

Nigel Armstrong

"Faraz" wrote:
Hi,
I am working with DOM and I need to do the following:

<sequence>
<element name="input1" type="string"/>
<element name="input2" type="string"/>
<element name="input3" type="string"/>
</sequence>
The problem is, I do not know how many inputs I will have until runtime. So
I have to generate the element Elements on the fly. One way to construct the
node would be like this:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<sequence>" +
"<element name='input1' type='string'/>" +
....and so on... +
"</seqence>");
MyDoc.ReplaceChild( doc, MyDoc.FirstChild ); or something along those lines

My question is, since I do not have a way of knowing how many inputs we have
until runtime, I have to put a for loop and name the inputs as input1,
input2....

How can I ge this 'input1' from my code which is doing this
for (int i = 0; i < numOfOperations; i++)
s = s + "<element name="+ 'input + i '+" type='string'/>");

I am getting 'input+i' instead of input1. Is there any way to force the
character to
convert the value instead of treating it as a literal??

Thanks
Faraz

Nov 16 '05 #2
three things I'd suggest:
1) learn to use the DOM. You can create the child node and simply append it
to the list of nodes. No need for string manipulations like this.

2) take a look at the StringBuilder class. If you are going to concatenate
large numbers of strings, you will be very wasteful of memory, since strings
in .NET are immutable. This means that they do not change. In other words,
if you create a string, and append a single character, an entirely new
string is created, and both of the two operands are discarded.
StringBuilder doesnt' do this.

3) Your problem, below, can be fixed by moving a quote character around a
little. THe line:
s = s + "<element name="+ 'input + i '+" type='string'/>"); becomes s = s + "<element name=input" + i +" type='string'/>");

--- Nick

"Faraz" <Fa***@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com... Hi,
I am working with DOM and I need to do the following:

<sequence>
<element name="input1" type="string"/>
<element name="input2" type="string"/>
<element name="input3" type="string"/>
</sequence>
The problem is, I do not know how many inputs I will have until runtime. So I have to generate the element Elements on the fly. One way to construct the node would be like this:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<sequence>" +
"<element name='input1' type='string'/>" +
....and so on... + "</seqence>");
MyDoc.ReplaceChild( doc, MyDoc.FirstChild ); or something along those lines
My question is, since I do not have a way of knowing how many inputs we have until runtime, I have to put a for loop and name the inputs as input1,
input2....

How can I ge this 'input1' from my code which is doing this
for (int i = 0; i < numOfOperations; i++)
s = s + "<element name="+ 'input + i '+" type='string'/>");

I am getting 'input+i' instead of input1. Is there any way to force the
character to
convert the value instead of treating it as a literal??

Thanks
Faraz

Nov 16 '05 #3

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

Similar topics

8
by: Steven | last post by:
i need to force a carriage return with a textarea field at X number of characters. anybody know how to do this? tks
3
by: Ken Durden | last post by:
Is it possible to force positive values to have the + sign prefixed on them? double f1 = 1024.2; double f2 = -1024.2; string.Format( "{0:F}", f1 ); // +1024.2 string.Format( "{0:F}", f2 );...
2
by: ladino | last post by:
Hi: I'm testing DB2's new automated maintenance feature and, so far it seems to accomplish what it is instructed to do, but we (DBA's) have no control on when the evaluation cycle is going to...
8
by: morphex | last post by:
Hi, I'm a python programmer that's started to play a bit with C as I'll probably have to make C extensions eventually.. I made this little program that I'd like to get feedback on, it's...
5
by: Gary Wessle | last post by:
Hi I ran my code in gdb after it was giving me un-expected results, to find out why and I found where the problem is but I don't understand why it happened. if( username == us && password ==...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I force a reload from the server/prevent caching?...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.