|
Vishnu Narayan Mishra wrote: How we pass parameter into String.Format pls tell m?
I don't think I understand your question. You have read the documentation[^] yes?
|
|
|
|
|
hello every one...
can you help me to sort out a little problem of xml?
how can we go through such kinds of tag in xml like <PopupHTML />
and make it complete pair tag like that <PopupHTML> </PopupHTML> using c#
this is the sample structure of my XML file...
please reply me soon sir thank you...
--------------------------------------------------------------
<FieldsToSupport>
<FieldToSupport>
<Caption>Blank</Caption>
<Url>Blank</Url>
<Label>NewField1</Label>
<HtmlName />
<HtmlId />
<FieldUniqueId>15b85c2b-83ca-44ec-8741-22a4dc64f64d</FieldUniqueId>
<LinkHref>http://careers.msn.com/</LinkHref>
<InnerHTML>Careers &amp; Jobs</InnerHTML>
<OuterHTML><A href="http://careers.msn.com">Careers &amp; Jobs</A></OuterHTML>
<PopupHTML />
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
</FieldToSupport>
<FieldToSupport>
...
</FieldToSupport>
<FieldToSupport>
...
</FieldToSupport>
<FieldsToSupport>
--------------------------------------------------------------
|
|
|
|
|
You need to read the documentation, and there are a lot of examples available on Code Project and the rest of the internet. Anyways, here is an example:
using System;
using System.Xml;
namespace XmlExample
{
class Program
{
static void Main(string[] args)
{
string xml =
"<?xml version='1.0'?>\n"
+ "<nodes>\n"
+ "\t<node/>\n"
+ "</nodes>\n";
XmlDocument xml_doc = new XmlDocument();
xml_doc.PreserveWhitespace = true;
xml_doc.LoadXml(xml);
XmlNode node = xml_doc.SelectSingleNode("//nodes/node");
if (node != null)
{
XmlText text = xml_doc.CreateTextNode("Hello, World!");
node.AppendChild(text);
}
Console.WriteLine(xml_doc.InnerXml);
}
}
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hello every one! I have a little problem of deleting xml node. I have deleted successfully the
attributes of node <ScreenSupportItem> but opening and closing tag of node was not deleted
<ScreenSupportItem> and </ScreenSupportItem>.
But i have to delete also the opening and clsing tag ofthe node <ScreenSupportItem> means I have to
remove every thing of <ScreenSupportItem>.How can I do this.
following is the structure 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>
<ScreenUniqueId>c1f13323-209b-4b0e-ad8d-d34f64d34c28</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
<LinkDate>2007-10-25T11:47:10.515625+05:30</LinkDate>
<LinkAuthor>SUBHASH\Login Subhash</LinkAuthor>
<LinkURL>C:\Documents and Settings\Login Subhash\Desktop\main.html</LinkURL>
<LinkText>Adding New Html Help</LinkText>
<OptionalSupportInstruction />
<RefId>3</RefId>
</ScreenSupportItem>
<ScreenSupportItem>
...
</ScreenSupportItem>
<ScreenSupportItem>
....
</ScreenSupportItem>
</SupportItems>
</ScreensToSupport>
</LinkInformation>
--------------------------------------------------------
following is my c# code
--------------------------------------------------------
//int intRefId = Convert.ToInt32(Request.QueryString["RefId"]);
int intRefId = 3;
string strXPath =
"/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" +
intRefId + "']";
XmlNode newParent = doc.SelectSingleNode(strXPath);
XmlNodeList newChildNodeList = newParent.ParentNode.ChildNodes;
foreach (XmlNode node1 in newChildNodeList)
{
foreach (XmlNode node in node1)
{
if (node.Name == "LinkURL" && node.InnerText == hdntxtUrlLink.Text)
{
intCount++;
}
if (node.Name == "LinkText" && node.InnerText == hdntxtUrlTitle.Text)
{
intCount++;
}
}
if (intCount == 2)
{
node1.RemoveAll();// This line deleted successfully the node but it left
start and end tag of the node <ScreenSupportItem> and </ScreenSupportItem>
lblError.Text = "Deleted successfully !";
break;
}
}
doc.Save(strXMLFile);
--------------------------------------------------------
please reply me soon.
Thanks in advance..
Vishnu
|
|
|
|
|
Use an XPath statement to find the node you want to remove then call
node.ParentNode.RemoveChild(node)<br />
<br />
XmlNode node = doc.SelectSingleNode("//x/y/z/ScreenSupportItem");
node.ParentNode.RemoveChild(node);
|
|
|
|
|
Thanks a lot sir, its working fine....
|
|
|
|
|
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
|
|
|
|
|
Hello every one..
There is a little problem of xml..?
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> //can be same for two or more childs
</ScreensToSupport>
<ScreenToSupport>
....
</ScreensToSupport>
<ScreenToSupport>
.....
</ScreenToSupport>
</ScreensToSupport>
</LinkInformation>
-----------------------------
following is my code..
please reply me soon sir .. i will very thankful for that..
-----------------------------
int intRefId = Convert.ToInt32(Request.QueryString["RefId"]);
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
{
//insert new <ScreenSupportItem>...
doc.Save(strXMLFile);
}
}
}
-------------------------------
-- modified at 3:28 Tuesday 13th November, 2007
|
|
|
|
|
<?xml version="1.0"?>
<configuration>
<appSettings />
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" />
<roleManager enabled="true" />
<authentication mode="Forms">
<forms loginUrl="Login.aspx" path="/" defaultUrl="Default.aspx" cookieless="UseDeviceProfile">
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
<location path="UnauthorizedAccess.aspx">
<system.web>
<authorization>
<allow roles="Administrator" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Admin">
<system.web>
<authorization>
<allow roles="Manager" />
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
How we select dynamically the location tag from a web.config if we have 2 0r 3 location tag is avilable.In the above webconfig file we have 2 location tag.I want to change the path of the location tag dynamically.Please help to overcome this problem.
|
|
|
|
|
Try the XML tutorial at www.w3schools.com
|
|
|
|
|
hello every one I am tried to update an XML file but its not working according to my requirement. I have to create a new child node <screensupportitem> below the parent node <supportitems> with matching condition --where attribute of <screensupportitem> e.g <refid> is equal to 3 (comes from query string). Also new <screensupportitem> child have different attributes except <refid>. So I have to create a <screensupportitem> with setting new values of all the attributes.
This is the structure of XML file
-----------------------------------------------------------------
<screenstosupport>
<screentosupport>
........all have same structure <screentosupport>
<screentosupport>
<screenuniqueid>c1f13323-209b-4b0e-ad8d-d34f64d34c28
<supportitems>
<linkurl>C:\Documents and Settings\Login Subhash\Desktop\iframe.html
<linktext>New Link Help
<screensupportitem>
<linkdate>2007-10-25T11:47:10.515625+05:30
<linkauthor>SUBHASH\Login Subhash
<linkurl>C:\Documents and Settings\Login Subhash\Desktop\main.html
<linktext>Adding New Html Help
<optionalsupportinstruction>
<refid>3
<fieldstosupport>
<linkurl>C:\Documents and Settings\Login Subhash\Desktop\iframe.html
<linktext>New Link Help
<screentosupport>
........all have same structure <screentosupport>
And this is my sample code
-----------------------------------------------------------------
strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strXMLFile);
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;
XmlNode newRootParent = doc.SelectSingleNode(strXPath).ParentNode;
XmlNode newScreenToSupport = newParent.Clone();
newRootParent.InsertAfter(newRootParent, newScreenToSupport);
doc.Save(strXMLFile);
-----------------------------------------------------------------
It giving error 'ERROR:Cannot insert a node or any ancestor of that node as a child of itself.'
I am very new in xml please help me to solved my problem. I will very thankful for your valuable cooperation.
Please reply me soon....
|
|
|
|
|
Vishnu Narayan Mishra wrote: newRootParent.InsertAfter(newRootParent, newScreenToSupport);
As the error message explains, you are adding a node as a child of itself here. Read the MSDN documentation[^] on this method if you are unsure how to use it.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
am writing an app that uses the .Net classes TCPClient and NetworkStream to read and write data between 2 machines. All works fine.
I have recently found a need to be able to send Http 1.1 with a SOAP message as the Http body. Currently i am using an XmlDocument to load and parse the SOAP data. However to do this i first have to read in the HTTP header, search for the beginning of the body and construct my own XmlDocument.
There must be a better way. I don't want to call a web service, i just want to send http with a soap body and receive the same.
I am looking for a means of loading in the NetworkStream into some kind of HTTP object to read the http stuff and also load the body into some simple Soap object that can be used to pull out/ set values.
Comments, Suggestions Welcomed.
Carl
|
|
|
|
|
Please don't double post.
Choose the most appropriate forum for your question and ask there only.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hi everyone,
Im a newbie in xml, anyone could help to resolve my problem?
I have one xml file and i was able to fill my two datagrid (grdColor and grdSize) using my PO.xml data.Now, my problem is i would like to filter my data in grdSize depending to the data in the grdColor.Like for example, in the grdColor i have two rows, the first row has a ColorID: 1 and the second row is ColorID:2, now , when the mouse cursor pointing to the first row which ColorID is 1 in grdSize it only appear thus data that has ColorID:1.
Thanks in advance.
try and try until you success..
|
|
|
|
|
kurt19 wrote: I have one xml file and i was able to fill my two datagrid (grdColor and grdSize) using my PO.xml data.
Ummm..... how?
|
|
|
|
|
that's my problem right now. Hope someone can help me this problem.
try and try until you success..
|
|
|
|
|
It appears you are not having a problem with XML but with an ASP.NET Datagrid.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
My problem is I could not filter the data appears in my second datagrid. Because when i load my xml file it will simply populate the two datagrid. My first datagrid is consist of Parent nodes while my second datagrid are the child nodes.
What i want to do is when i load the xml file the first datagrid will display all data while the display data in the second datagrid depends on the first grid.HOw could I filter the data in the second grid?
try and try until you success..
|
|
|
|
|
I can think of two ways of filtering your data. First, you can filter the child XML document based on the parent XML document using XSLT, and binding the resulting XML document to the child Datagrid. Second, you can place both XML documents in the same Dataset into their corresponding Datatables. You create a DataRelation and a DataView to achieve your desired results.
You can find articles on Code Project to get you started or you can Google for more resources and examples.
George
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi george,
Thanks, but I have only one XML file. How could I manipulate this kind of proble. Can you give me an example code that related to my problem.
Thanks in advance.
Regards,
kurt
try and try until you success..
|
|
|
|
|
As I said, your problem is with DataGrids. This is the XML/XSL forum. In your case, your XML document is just a data source and you want to display it in a certain way. I guess you want a Master-Detail type report. So, look on Code Project and Google for your example code. I gave you keys to help your search.
Also, if using a DataGrid is to complicated for you. You know you can create your own table and post it to the ASP.NET page.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
I had created an XML file with Unicode (encoding UTF-8) using Word 2007; the problem is when I try to view it in IE through an XSL result in the following error:
An invalid character was found in text content...
I changed the encoding of XML file to “ISO-8859-1” – able to view in IE but the characters get messed.
Please Help.
Hariharan C
|
|
|
|
|
Hariharan2105 wrote: I changed the encoding of XML file to “ISO-8859-1”
ummm.... how?
|
|
|
|
|
Hi,
did you try to set the output of your sxl file to utf-8 or iso-8859-1?
example:
<xsl:output method="xml" encoding="iso-8859-1" indent="yes" />
otherwise, some more information might be needed to know where the encoding gets messed up.
|
|
|
|