Click here to Skip to main content
15,886,518 members
Home / Discussions / XML / XSL
   

XML / XSL

 
GeneralRe: how to fetch child nodes of parent node in XML .. using c#... Pin
Vishnu Narayan Mishra19-Nov-07 20:03
Vishnu Narayan Mishra19-Nov-07 20:03 
GeneralRe: how to fetch child nodes of parent node in XML .. using c#... Pin
led mike20-Nov-07 5:39
led mike20-Nov-07 5:39 
Questionhow can we go through such kinds of tag in xml like <PopupHTML /> Pin
Vishnu Narayan Mishra13-Nov-07 23:17
Vishnu Narayan Mishra13-Nov-07 23:17 
AnswerRe: how can we go through such kinds of tag in xml like Pin
George L. Jackson14-Nov-07 1:53
George L. Jackson14-Nov-07 1:53 
QuestionHow to delete a xml node with all attributes and start, end tag of the xml node in c#-- urgent Pin
Vishnu Narayan Mishra13-Nov-07 2:17
Vishnu Narayan Mishra13-Nov-07 2:17 
AnswerRe: How to delete a xml node with all attributes and start, end tag of the xml node in c#-- urgent Pin
led mike13-Nov-07 6:18
led mike13-Nov-07 6:18 
GeneralRe: How to delete a xml node with all attributes and start, end tag of the xml node in c#-- urgent Pin
Vishnu Narayan Mishra13-Nov-07 22:24
Vishnu Narayan Mishra13-Nov-07 22:24 
QuestionHow can I go through all child nodes and attributes of child nodes of a parent node.. Pin
Vishnu Narayan Mishra12-Nov-07 22:22
Vishnu Narayan Mishra12-Nov-07 22:22 
Hello sir

There is a little problem of xml again.
How can I go through all child nodes and attributes of child nodes of a parent node..

Suppose i have to go through all child nodes e.g.<ScreenSupportItem> of parent nodes

e.g.<SupportItems>. There can be mutiple <ScreenSupportItem> in a parent node <SupportItems>. I have

to check values of <LinkURL> and <LinkText> of all child nodes <ScreenSupportItem> and if it matches

with the supplied valus it gives a message 'LinkUrl/LinkText already exist' else insert new

<ScreenSupportItem> of <ScreenSupportItem> and set all attributes of <ScreenSupportItem> , which was

supplied by the user.
My code check only first child <ScreenSupportItem> of <SupportItems> if it values matches for

<LinkURL> and <LinkText> give a proper message else insert new <ScreenSupportItem>.
So how can I check all child <ScreenSupportItem> for values <LinkURL> and <LinkText> of

<SupportItems>

This is a sample struture of my XML file
----------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinkInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LinkToolId>0</LinkToolId>
<LinkToolVersion>1.0.1</LinkToolVersion>

<ScreensToSupport>
<ScreenToSupport>
<LinkDate>2007-11-13T12:48:29.9687500+05:30</LinkDate>
<LinkAuthor>SUBHASH\vishnu</LinkAuthor>
<LinkURL>C:\Documents and Settings\Login Subhash\Desktop\iframe.html</LinkURL>
<LinkText>HTML Help File</LinkText>
<OptionalSupportInstruction />
<RefId>3</RefId>
</ScreenToSupport>

<ScreenToSupport>
<LinkDate>2007-11-13T13:04:40.2656250+05:30</LinkDate>
<LinkAuthor>SUBHASH\vishnu</LinkAuthor>
<LinkURL>C:\Documents and Settings\Login Subhash\Desktop\main.html</LinkURL>
<LinkText>Adding new Help Link</LinkText>
<OptionalSupportInstruction />
<RefId>3</RefId>
</ScreensToSupport>

<ScreenToSupport>
<LinkDate>2007-11-13T13:04:24.8437500+05:30</LinkDate>
<LinkAuthor>SUBHASH\vishnu</LinkAuthor>
<LinkURL>C:\Documents and Settings\Login Subhash\Desktop\iframeCopy.html</LinkURL>
<LinkText>New Link Help</LinkText>
<OptionalSupportInstruction />
<RefId>3</RefId>
</ScreensToSupport>

<ScreenToSupport>
.....
</ScreenToSupport>

</ScreensToSupport>

</LinkInformation>
----------------------------------------------------------------


follwing is my code..
please reply me soon sir .. i will very thankful for that..
----------------------------------------------------------------
if (strAlbumName != "" && strAlbumPath != "")
{
strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strXMLFile);

System.Data.DataSet objDataSet = new DataSet();

FileStream findata = new FileStream(strXMLFile, FileMode.Open, FileAccess.Read,

FileShare.ReadWrite);
objDataSet.ReadXml(findata);
findata.Close();
//int intRefId = Convert.ToInt32(Request.QueryString["RefId"]);
int intRefId = 3;
string strFilePath = FileUpload.PostedFile.FileName;
string strXPath =

"/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" +

intRefId + "']";

XmlNode newParent =

doc.SelectSingleNode(strXPath);//.ParentNode.NextSibling.ChildNodes;

foreach (XmlNode node in newParent)
{
if (node.Name == "LinkURL")
{
if (node.InnerText == FileUpload.PostedFile.FileName)
{
BaydonConstants.flag = true;
break;
}
}
else if (node.Name == "LinkText")
{
if (node.InnerText == txtUrlTitle.Text)
{
BaydonConstants.flag = true;
break;
}
}
}
if (BaydonConstants.flag == true)
{
lblError.Text = "LinkUrl/LinkText already exist !";
BaydonConstants.flag = false;
}
else
{
string strMachineName = System.Environment.MachineName + "\\";
XmlNode newRootParent = doc.SelectSingleNode(strXPath).ParentNode;
int intNodeCount = newRootParent.ChildNodes.Count;
if (intNodeCount == 1 && (newParent["LinkURL"].InnerText.ToString() == "" &&

newParent["LinkText"].InnerText.ToString() == ""))
{
newParent["LinkDate"].InnerText = DateTime.Now.ToString("o");
newParent["LinkAuthor"].InnerText = strMachineName +

Session["UserId"].ToString();
newParent["LinkURL"].InnerText = FileUpload.PostedFile.FileName;
newParent["LinkText"].InnerText = txtUrlTitle.Text;
lblError.Text = "Inserted successfully !";
}
else
{
XmlNode newScreenToSupport = newParent.Clone();
newScreenToSupport["LinkDate"].InnerText = DateTime.Now.ToString("o");
newScreenToSupport["LinkAuthor"].InnerText = strMachineName +

Session["UserId"].ToString();
newScreenToSupport["LinkURL"].InnerText = FileUpload.PostedFile.FileName;
newScreenToSupport["LinkText"].InnerText = txtUrlTitle.Text;

newRootParent.InsertBefore(newScreenToSupport, newParent);
lblError.Text = "Inserted successfully !";
}
doc.Save(strXMLFile);
}
}
}
----------------------------------------------------------------

Vishnu Narayan
QuestionHow can I go through all child nodes and attributes of child nodes of a parent node.. [modified] Pin
Vishnu Narayan Mishra12-Nov-07 21:14
Vishnu Narayan Mishra12-Nov-07 21:14 
QuestionEdititng the tag of XML Pin
SreejithAchutan8-Nov-07 17:04
SreejithAchutan8-Nov-07 17:04 
AnswerRe: Edititng the tag of XML Pin
led mike9-Nov-07 5:19
led mike9-Nov-07 5:19 
Questionhow to append node with attributes after an node in XML + C# [modified] Pin
Vishnu Narayan Mishra7-Nov-07 20:52
Vishnu Narayan Mishra7-Nov-07 20:52 
AnswerRe: how to append node with attributes after an node in XML + C# Pin
pmarfleet8-Nov-07 9:51
pmarfleet8-Nov-07 9:51 
QuestionSending XML Soap Messages, C# Pin
AssemblySoft5-Nov-07 6:18
AssemblySoft5-Nov-07 6:18 
AnswerDouble post Pin
pmarfleet5-Nov-07 6:54
pmarfleet5-Nov-07 6:54 
QuestionXML problems Pin
kurt194-Nov-07 23:31
kurt194-Nov-07 23:31 
AnswerRe: XML problems Pin
led mike5-Nov-07 7:21
led mike5-Nov-07 7:21 
GeneralRe: XML problems Pin
kurt195-Nov-07 13:56
kurt195-Nov-07 13:56 
GeneralRe: XML problems Pin
George L. Jackson5-Nov-07 14:41
George L. Jackson5-Nov-07 14:41 
GeneralRe: XML problems Pin
kurt195-Nov-07 15:36
kurt195-Nov-07 15:36 
AnswerRe: XML problems Pin
George L. Jackson6-Nov-07 2:06
George L. Jackson6-Nov-07 2:06 
GeneralRe: XML problems Pin
kurt196-Nov-07 19:53
kurt196-Nov-07 19:53 
GeneralRe: XML problems Pin
George L. Jackson7-Nov-07 0:04
George L. Jackson7-Nov-07 0:04 
QuestionEncoding UTF-8 vs iso-8859-1 Pin
Hariharan21052-Nov-07 2:55
Hariharan21052-Nov-07 2:55 
AnswerRe: Encoding UTF-8 vs iso-8859-1 Pin
led mike5-Nov-07 7:22
led mike5-Nov-07 7:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.