473,785 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("<s equence>" +
"<element name='input1' type='string'/>" +
....and so on... +
"</seqence>");
MyDoc.ReplaceCh ild( doc, MyDoc.FirstChil d ); 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 1769
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("<s equence>" +
"<element name='input1' type='string'/>" +
....and so on... +
"</seqence>");
MyDoc.ReplaceCh ild( doc, MyDoc.FirstChil d ); 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***@discussi ons.microsoft.c om> wrote in message
news:62******** *************** ***********@mic rosoft.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("<s equence>" +
"<element name='input1' type='string'/>" +
....and so on... + "</seqence>");
MyDoc.ReplaceCh ild( doc, MyDoc.FirstChil d ); 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
46180
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
28229
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 ); // -1024.2 I was hoping for something either in the string.Format prefix, or
2
4080
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 happen nor when the utilities are set to execute. We only supply 'time ranges' for DB2 to operate upon. What I want is a means to 'force' a new evaluation period (i.e. I'm creating and loading new tables and I want to force a new evaluation cycle...
8
1471
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 basically a find substring and return pointer to it function and tests for it.. Could this be done better/differently? Is anything fundamentally wrong?
5
1471
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 == pa ) { cout << "connected." << endl; on_off = true; } else {
1
1287
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I force a reload from the server/prevent caching? ----------------------------------------------------------------------- To reload a page, use location.reload(). However, this depends upon the cache headers that your server sends. To change this, you need to alter the server configuration. A quick fix on the client is to change the page URI so...
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.