473,406 Members | 2,293 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,406 software developers and data experts.

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 2502
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.MapPath("UserPass.xml");

doc.Load(url);

XmlNodeList UserList = doc.GetElementsByTagName("username");

int UserCount = UserList.Count;

DataTable dt = new DataTable();

DataRow dr;

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

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

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

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

{

dr = dt.NewRow();

XmlNode usernode = UserList.Item(i);

XmlElement userele = (XmlElement)usernode.ParentNode;

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

dr[1] = (usernode.InnerXml).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
programmatically 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!PLEASEtkachenko.com>
Newsgroups: microsoft.public.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!PLEASEtkachenko.com> wrote in message
news:eF**************@TK2MSFTNGP09.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.MapPath("UserPass.xml");

doc.Load(url);

XmlNodeList UserList = doc.GetElementsByTagName("username");
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
programmatically 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!PLEASEtkachenko.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
smita wrote:
The code for adding the rows is as given below

XmlDocument doc = new XmlDocument();

string url=Server.MapPath("UserPass.xml");

doc.Load(url);

XmlNodeList UserList = doc.GetElementsByTagName("username");


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
programmatically 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
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...
5
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...
10
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,...
5
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...
9
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...
0
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...
18
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,...
6
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...
2
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.