auto increment

publicclassAddAnnouncement

{

publicvoid _AddAnnouncement()

{

XmlDocument newAnnDoc =newXmlDocument();

newAnnDoc.Load("~/App_Data/Announcement.xml");

XmlNode newAnn = newAnnDoc.CreateNode(XmlNodeType.Element,"ann",null);

XmlNode Id = newAnnDoc.CreateNode(XmlNodeType.Element,"annID",null);

XmlNode Title = newAnnDoc.CreateNode(XmlNodeType.Element,"annTitle",null);

XmlNode Body = newAnnDoc.CreateNode(XmlNodeType.Element,"annBody",null);

XmlNode Date = newAnnDoc.CreateNode(XmlNodeType.Element,"annDate",null);

XmlNode Priority = newAnnDoc.CreateNode(XmlNodeType.Element,"annPriority",null);

XmlNode Sender = newAnnDoc.CreateNode(XmlNodeType.Element,"annSender",null);

XmlElement annPanel = newAnnDoc.DocumentElement;

annPanel.AppendChild(newAnn);

newAnn.AppendChild(Id);

newAnn.AppendChild(Title);

newAnn.AppendChild(Body);

newAnn.AppendChild(Date);

newAnn.AppendChild(Priority);

newAnn.AppendChild(Sender);

}

}

but i need when my method called i want that some child must add itself to xmlfile outo like annID,annDate

what is the way ; must i do it here or from my schema?

[3374 byte] By [Radith] at [2007-12-22]
# 1

here is my xml file;

<?xml version="1.0" encoding="iso-8859-9"?>

<annPanel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="AnnSchema.xsd" >

<ann>

<annID></annID>

<annTitle></annTitle>

<annBody></annBody>

<annDate></annDate>

<annPriority></annPriority>

<annSender></annSender>

</ann>

</annPanel>

it must seem like this but ID and Date must assign automatically;

Radith at 2007-8-30 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2

It's hard to understand what is the problem or what you want to achive.

Can you, please, reformulate your question.

Thanks.

SergeyDubinets-MSFT at 2007-8-30 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3

like this int a=0; and id.?( maybe value;;; i dont know what mus be after dot)=a; a++;

but i found my answer it is like this;

XmlDocument annDoc = new XmlDocument();

annDoc.Load("~/App_Code/Announcement.xml");

XmlNode nodeLast;

XmlNode root = annDoc.DocumentElement;

nodeLast = annDoc.SelectSingleNodes("//annPanel/ann[position()=last()]");

if (nodeLast != null)

return ++Convert.ToInt32(nodeLast.InnerText);

i wrote method like above codes and

id.value = getID(); in my first codes;

thanks your interest too much ;

your sincerely;

Radith at 2007-8-30 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 4

It's greate that you was able to find the answer.

You can find other properties of XmlNode: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxmldocumentclasscreatenodetopic.asp

SergeyDubinets-MSFT at 2007-8-30 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 5

public int GetID()

{

XmlDocument annDoc = new XmlDocument();

annDoc.Load("~/App_Code/Announcement.xml");

int annID = 0;

XmlNode nodeLast;

XmlNode root = annDoc.DocumentElement;

nodeLast = annDoc.SelectSingleNode("//annPanel/ann[position()=last()]");

if (nodeLast != null)

annID = Convert.ToInt32(nodeLast.InnerText);/// when i debug this code it gives to me

input wasnt in a corret format? why it can be ?

++annID;

return annID;

}

}

and above of my code i call getId method like this

int annID;

annID = GetID();

string strAnnID;

strAnnID = XmlConvert.ToString(annID);

XmlNode Id = newAnnDoc.CreateNode(XmlNodeType.Element, "annID", null);

Id.Value = strAnnID;

Radith at 2007-8-30 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 6

In debugger you can see what is the actual value of the InnerText property.

From you sample it mposible to deduct.

If this value is not a valid integer how you expect to increment it?

SergeyDubinets-MSFT at 2007-8-30 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified