473,789 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Xml Attribute..id problem??

Hi,
I have an xml file as below

<root>
<table id =1>
<user>abc</user>
<age>25</age>
</table>
<table id = 2>
<user>xyz</user>
<age>45</age>
</table>
.....
.....
</root>

What I want is this id attribute to increment automatically.
So I declared it of type "ID" ..but how do i access the value of this
attribute.

When i add a record it gets added to the xml file but the id attribute does
not show..So how do i refer to this attribute.
Nov 12 '05 #1
4 2524
smita wrote:
What I want is this id attribute to increment automatically. For starters, ID in XML cannot be a number. It must be a name.
So I declared it of type "ID" ..but how do i access the value of this
attribute.

When i add a record it gets added to the xml file but the id attribute does
not show..So how do i refer to this attribute.

Well, you forgot to explain which API you are using for getting values
and adding rows.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com
Nov 12 '05 #2
The code for adding the rows is as given below

XmlDocument doc = new XmlDocument();

string url=Server.MapP ath("UserPass.x ml");

doc.Load(url);

XmlNodeList UserList = doc.GetElements ByTagName("user name");

int UserCount = UserList.Count;

DataTable dt = new DataTable();

DataRow dr;

dt.Columns.Add( new DataColumn("ID" , typeof(string)) );

dt.Columns.Add( new DataColumn("Use rs", typeof(string)) );

dt.Columns.Add( new DataColumn("Sel ect to Edit", typeof(string)) );

dt.Columns.Add( new DataColumn("Sel ect to Delete", typeof(string)) );
for (int i = 0; i < UserCount; i++)

{

dr = dt.NewRow();

XmlNode usernode = UserList.Item(i );

XmlElement userele = (XmlElement)use rnode.ParentNod e;

dr[0] = userele.GetAttr ibute("id");

dr[1] = (usernode.Inner Xml).ToString() ;

dr[2] = "EDIT";

dr[3] = "DELETE";

dt.Rows.Add(dr) ;

}

DataView dv = new DataView(dt);

UserDetailsGrid .DataSource = dv;

UserDetailsGrid .DataBind();

Now it does not display the id value in the data grid. I want to refer to
this value depending on which particular users Edit or Delete link has been
clicked..so I need the value for id. If i add this attribute
programmaticall y and increment it after adding each user ...i face a problem
when deleting the users ...because if the 10th user has been deleted i wud
need to update the id of all the remaining users ...which does not make
sense...so this has to be done automaticaaly..

Any Advice wud be helpful...

Thanx,

Smita.



----- Original Message -----
From: "Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com>
Newsgroups: microsoft.publi c.dotnet.xml
Sent: Sunday, January 25, 2004 1:51 PM
Subject: Re: Xml Attribute..id problem??

smita wrote:
What I want is this id attribute to increment automatically. For starters, ID in XML cannot be a number. It must be a name.
So I declared it of type "ID" ..but how do i access the value of this
attribute.

When i add a record it gets added to the xml file but the id attribute does not show..So how do i refer to this attribute.

Well, you forgot to explain which API you are using for getting values
and adding rows.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com

"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:eF******** ******@TK2MSFTN GP09.phx.gbl... smita wrote:
What I want is this id attribute to increment automatically.

For starters, ID in XML cannot be a number. It must be a name.
So I declared it of type "ID" ..but how do i access the value of this
attribute.

When i add a record it gets added to the xml file but the id attribute does not show..So how do i refer to this attribute.

Well, you forgot to explain which API you are using for getting values
and adding rows.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com

Nov 12 '05 #3
smita wrote:
The code for adding the rows is as given below

XmlDocument doc = new XmlDocument();

string url=Server.MapP ath("UserPass.x ml");

doc.Load(url);

XmlNodeList UserList = doc.GetElements ByTagName("user name");
Now it's even more confusing :( In XML you have posted there is no
username element. Show us UserPass.xml fragment so we can reproduce the
problem.
Now it does not display the id value in the data grid. I want to refer to
this value depending on which particular users Edit or Delete link has been
clicked..so I need the value for id. If i add this attribute
programmaticall y and increment it after adding each user ...i face a problem
when deleting the users ...because if the 10th user has been deleted i wud
need to update the id of all the remaining users ...which does not make
sense.


Instead of having explicit id you can calculate it every time as number
of the row in a table. Then it'll work automatically for deleting.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com
Nov 12 '05 #4
The table is like this...

<root>
<table id =1>
<username>abc </username>
<age>25</age>
</table>
<table id = 2>
<username>xyz </username>
<age>45</age>
</table>

"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:uB******** ******@TK2MSFTN GP10.phx.gbl...
smita wrote:
The code for adding the rows is as given below

XmlDocument doc = new XmlDocument();

string url=Server.MapP ath("UserPass.x ml");

doc.Load(url);

XmlNodeList UserList = doc.GetElements ByTagName("user name");


Now it's even more confusing :( In XML you have posted there is no
username element. Show us UserPass.xml fragment so we can reproduce the
problem.
Now it does not display the id value in the data grid. I want to refer to this value depending on which particular users Edit or Delete link has been clicked..so I need the value for id. If i add this attribute
programmaticall y and increment it after adding each user ...i face a problem when deleting the users ...because if the 10th user has been deleted i wud need to update the id of all the remaining users ...which does not make
sense.


Instead of having explicit id you can calculate it every time as number
of the row in a table. Then it'll work automatically for deleting.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com

Nov 12 '05 #5

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

Similar topics

2
3959
by: Bill Cohagan | last post by:
In my app I'm validating an XML file against an XSD which contains several attribute default value specifications. I'm performing the validation via an xml document load() using a ValidatingXMLReader. After loading the document (and validating it) I assume that the resulting doc will (as appropriate) have elements with attributes set to their default values in those cases where there was nothing specified in the input XML file. However,...
5
15184
by: Neil Norfolk | last post by:
I am using C# in Visual Studio 2003. I would like to serialize a class that contains, amongst other things, public delegate void DocumentsPreferencesChange(object env, Documents e); public event DocumentsPreferencesChange OnDocumentsPreferencesChange; However, as it stands, the classes containing any methods/delegates that have been added to OnDocumentsPreferencesChange also have to be serializable: this I do not want. I do not actually...
10
42969
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA attribute values are part of markup or not.) Thanks.
5
1533
by: AdSR | last post by:
Hi, I'm having a problem with the Amara toolkit. Try this: >>> from amara import binderytools >>> raw = '<pq:test xmlns="http://example.com/namespace" xmlns:pq="http://pq.com/ns2"/>' >>> rwd = binderytools.bind_string(raw) >>> print rwd.xml() <?xml version="1.0" encoding="UTF-8"?> <pq:test xmlns:pq="http://pq.com/ns2"/>
9
2500
by: =?Utf-8?B?d2luZHNpbQ==?= | last post by:
Hi, I have a project based on .Net 1.1 and VS 2003,now I am trying to upgrade it to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but When I start Debug, it suddenly comes StackOverflowException and Debug stops. The main Exception point is the function below: public System.ComponentModel.PropertyDescriptorCollection GetStatefulPropertyDescriptors() {
0
1622
by: pradip sonar | last post by:
Hello, I am having a problem with Xalan transforming a document containing Japanese characters. (An initial note: the problem does not occur on my Windows development machine, only on the Solaris test/production environments.) The basic problem is that for any place I'm selecting XML node values to use within an xsl:attribute block, if the text is double-byte it is converted to the NCR representation instead of the actual...
18
6785
by: Gabriel Rossetti | last post by:
Hello everyone, I had read somewhere that it is preferred to use self.__class__.attribute over ClassName.attribute to access class (aka static) attributes. I had done this and it seamed to work, until I subclassed a class using this technique and from there on things started screwing up. I finally tracked it down to self.__class__.attribute! What was happening is that the child classes each over-rode the class attribute at their level,...
6
7707
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute using an XPathNodeIterator? Or should I be using something else? In the sample that follows: 1. Grab all "Page" nodes. 2. Loop through all the nodes.
2
8760
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico file, but I have been unable to get any of the overloads to work in VB.NET. I would like to store the *.ico files in a *.resx file so that users do not need anything other than the *.dll, but at the moment I am just trying to get any of the overloads...
0
9663
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
10195
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
10136
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,...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6765
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.