Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
New Feature: Community Sites:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
|
insert values in xml
Posted Date:
29 Aug 2008
Total Responses:
1
|
Posted By: supriya Member Level: Bronze Points: 1
|
<category name="Introducing Seattle"> <image> <date>03.31.06</date> <title>View of Seattle</title> <desc>View of Seattle</desc> </image> </category>
from above like that only values will be inserted
|
Responses
|
| Author: ANIL PANDEY 29 Aug 2008 | Member Level: Diamond | Rating: Points: 1 | hi,
u can refer the following code to create a XML file
public XmlDocument get_AllArticle(int lintID) { BLL_Issue BobjIssue = new BLL_Issue(); BLL_Author BobjAuthor = new BLL_Author(); BLL_Search BobjSearch = new BLL_Search(); BLL_Resource BobjRes = new BLL_Resource();
int intCounter; string strTitle; string strTopic; string strAuthor; string strFname; string strLname; string strSummary; string strFileContent; string strAff; string strText; string strID; string strServerIP; char[] chrArray = { (char)34 }; string strQuote = chrArray.ToString(); DateTime dtIDate;
DataSet lds = new DataSet(); DataSet ldsIssue = new DataSet(); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); XmlDocument xmlDoc = new XmlDocument();
//Getting the ServerIP strServerIP = BobjRes.GetServerIP();
//Getting the IssueId or ArticleId if (lintID == 0) { string ID; ID = Convert.ToString((SqlHelper.ExecuteScalar(strConnStr, CommandType.Text, "select top 1 ID from tbIssues where IsArchive='true' order by issueDate desc "))); lintID = Convert.ToInt32(ID.ToString()); }
lds = SqlHelper.ExecuteDataset(strConnStr, CommandType.Text, "select * from tbArticles where IssueId=" + lintID + " order by ArticleOrderNo");//BobjSearch.getArticleById(lintID); ldsIssue = SqlHelper.ExecuteDataset(strConnStr, CommandType.Text, "select ID,VolumeNo,IssueNo,convert(VARCHAR, IssueDate,107) as IssueDate,PDFFileName,IsArchive from tbIssues where ID=" + lintID);//Convert.ToInt32(.ToString());
XmlTextWriter tw = new XmlTextWriter(sw); tw.Formatting = Formatting.Indented; //for xml tags to be indented// tw.WriteStartDocument(); tw.WriteStartElement("issue"); tw.WriteAttributeString("issueid", ldsIssue.Tables[0].Rows[0]["ID"].ToString()); tw.WriteAttributeString("issueno", ldsIssue.Tables[0].Rows[0]["IssueNo"].ToString()); tw.WriteAttributeString("volume", ldsIssue.Tables[0].Rows[0]["VolumeNo"].ToString()); dtIDate = Convert.ToDateTime(ldsIssue.Tables[0].Rows[0]["IssueDate"].ToString()); tw.WriteAttributeString("date", dtIDate.ToString("MMMM d, yyyy")); tw.WriteAttributeString("archive", ldsIssue.Tables[0].Rows[0]["IsArchive"].ToString()); if (ldsIssue.Tables[0].Rows[0]["PDFFileName"].ToString().Trim() != "") { tw.WriteAttributeString("urlpath", "../uploads/Issue/" + ldsIssue.Tables[0].Rows[0]["PDFFileName"].ToString()); } else { tw.WriteAttributeString("urlpath", "UserPages/printarticle.aspx?pt=" + lintID); }
if (strServerIP != "") { tw.WriteAttributeString("serverip", strServerIP); }
tw.WriteStartElement("articles"); for (intCounter = 0; intCounter < lds.Tables[0].Rows.Count; intCounter++) { strFileContent = lds.Tables[0].Rows[intCounter]["Contents"].ToString(); string title = string.Empty; XmlDocument doc = new XmlDocument(); doc.Load(new StringReader(strFileContent)); XmlNodeList articleList = doc.GetElementsByTagName("article"); tw.WriteStartElement("article");
foreach (XmlNode node in articleList) { XmlElement articleElement = (XmlElement)node;
strID = articleElement.GetElementsByTagName("id")[0].InnerText; tw.WriteAttributeString("id", strID);
strTopic = articleElement.GetElementsByTagName("topic")[0].InnerText; tw.WriteElementString("topic", strTopic);
strTitle = articleElement.GetElementsByTagName("title")[0].InnerText; tw.WriteElementString("title", strTitle);
tw.WriteStartElement("authors"); XmlNodeList authorList = doc.GetElementsByTagName("authors"); foreach (XmlNode node1 in authorList) { tw.WriteStartElement("author"); XmlElement authorElement = (XmlElement)node1;
strFname = authorElement.GetElementsByTagName("fname")[0].InnerText; tw.WriteElementString("fname", strFname);
strLname = authorElement.GetElementsByTagName("lname")[0].InnerText; tw.WriteElementString("lname", strLname);
strAuthor = authorElement.GetElementsByTagName("suffix")[0].InnerText;
if (strAuthor != "") { tw.WriteElementString("suffix", strAuthor); }
strAff = authorElement.GetElementsByTagName("affiliation")[0].InnerText;
tw.WriteElementString("affiliation", strAff); tw.WriteEndElement(); } tw.WriteEndElement();
strSummary = articleElement.GetElementsByTagName("summary")[0].InnerText; tw.WriteElementString("summary", strSummary);
strText = articleElement.GetElementsByTagName("text")[0].InnerText; tw.WriteElementString("text", strText); tw.WriteEndElement(); } }
tw.WriteEndElement(); tw.WriteEndElement(); tw.Close(); tw.Flush(); xmlDoc.LoadXml(sb.ToString()); return xmlDoc; }
// Function for Getting the XML Document For PDF Generation. public XmlDocument get_AllArticleForPDF(int lintID) { BLL_Issue BobjIssue = new BLL_Issue(); BLL_Author BobjAuthor = new BLL_Author(); BLL_Search BobjSearch = new BLL_Search(); BLL_Resource BobjRes = new BLL_Resource();
int intCounter; string strTitle; string strTopic; string strAuthor; string strFname; string strLname; string strFileContent; string strAff; string strText; string strID; string strServerIP; char[] chrArray = { (char)34 }; string strQuote = chrArray.ToString(); DateTime dtIDate;
DataSet lds = new DataSet(); DataSet ldsIssue = new DataSet(); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); XmlDocument xmlDoc = new XmlDocument();
//Getting the ServerIP strServerIP = BobjRes.GetServerIP();
//Getting the IssueId or ArticleId if (lintID == 0) { string ID; ID = Convert.ToString((SqlHelper.ExecuteScalar(strConnStr, CommandType.Text, "select top 1 ID from dbo.tbIssues where IsArchive='true' order by issueDate desc "))); lintID = Convert.ToInt32(ID.ToString()); } lds = SqlHelper.ExecuteDataset(strConnStr, CommandType.Text, "select ID,IssueId,Contents,ArticleOrderNo,ModifiedBy,ModifiedDate from dbo.tbArticles where IssueId=" + lintID + " order by ArticleOrderNo");//BobjSearch.getArticleById(lintID); ldsIssue = SqlHelper.ExecuteDataset(strConnStr, CommandType.Text, "select ID,VolumeNo,IssueNo,convert(VARCHAR, IssueDate,107) as IssueDate,PDFFileName,IsArchive from dbo.tbIssues where ID=" + lintID);//Convert.ToInt32(.ToString());
XmlTextWriter tw = new XmlTextWriter(sw); tw.Formatting = Formatting.Indented; //for xml tags to be indented// tw.WriteStartDocument(); tw.WriteStartElement("issue"); tw.WriteAttributeString("issue", ldsIssue.Tables[0].Rows[0]["ID"].ToString()); tw.WriteAttributeString("issueno", ldsIssue.Tables[0].Rows[0]["IssueNo"].ToString()); tw.WriteAttributeString("volume", ldsIssue.Tables[0].Rows[0]["VolumeNo"].ToString()); dtIDate = Convert.ToDateTime(ldsIssue.Tables[0].Rows[0]["IssueDate"].ToString()); tw.WriteAttributeString("date", dtIDate.ToString("MMMM d, yyyy")); tw.WriteAttributeString("archive", ldsIssue.Tables[0].Rows[0]["IsArchive"].ToString()); if (ldsIssue.Tables[0].Rows[0]["PDFFileName"].ToString().Trim() != "") { tw.WriteAttributeString("urlpath", "../uploads/Issue/" + ldsIssue.Tables[0].Rows[0]["PDFFileName"].ToString()); } else { tw.WriteAttributeString("urlpath", "UserPages/printarticle.aspx?pt=" + lintID); }
if (strServerIP != "") { tw.WriteAttributeString("serverip", strServerIP); }
tw.WriteStartElement("articles"); int intTopicSrNo = 0; for (intCounter = 0; intCounter < lds.Tables[0].Rows.Count; intCounter++) { strFileContent = lds.Tables[0].Rows[intCounter]["Contents"].ToString(); string title = string.Empty; XmlDocument doc = new XmlDocument(); doc.Load(new StringReader(strFileContent)); XmlNodeList articleList = doc.GetElementsByTagName("article"); tw.WriteStartElement("article");
intTopicSrNo++; foreach (XmlNode node in articleList) { XmlElement articleElement = (XmlElement)node;
strID = articleElement.GetElementsByTagName("id")[0].InnerText; tw.WriteAttributeString("id", strID);
strTopic = articleElement.GetElementsByTagName("topic")[0].InnerText; //tw.WriteElementString("topic", strTopic);
tw.WriteStartElement("topic"); tw.WriteAttributeString("id",Convert.ToString(intTopicSrNo)); tw.WriteString(strTopic); tw.WriteEndElement();
strTitle = articleElement.GetElementsByTagName("title")[0].InnerText; tw.WriteElementString("title", strTitle);
XmlNodeList authorList = doc.GetElementsByTagName("authors"); string strAuthorFullName = string.Empty; foreach (XmlNode node1 in authorList) { XmlElement authorElement = (XmlElement)node1; strFname = authorElement.GetElementsByTagName("fname")[0].InnerText; strLname = authorElement.GetElementsByTagName("lname")[0].InnerText; strAuthor = authorElement.GetElementsByTagName("suffix")[0].InnerText; strAff = authorElement.GetElementsByTagName("affiliation")[0].InnerText; strAuthorFullName = "";
if (strAuthor != "") { strAuthorFullName = strFname + " " + strLname + " " + strAuthor; } else { strAuthorFullName = strFname + " " + strLname; } if (strAuthorFullName.Trim() == "") { tw.WriteElementString("authors", ""); } else { tw.WriteElementString("authors", strAuthorFullName); } tw.WriteElementString("affiliations",""); } strText = articleElement.GetElementsByTagName("text")[0].InnerText; tw.WriteElementString("fulltext", strText); tw.WriteEndElement(); } }
tw.WriteEndElement(); tw.WriteEndElement(); tw.Close(); tw.Flush(); xmlDoc.LoadXml(sb.ToString()); return xmlDoc; } #endregion
thanks anil
Thanks & Regards Anil Kumar Pandey
|
| Post Reply |
|
|
|
You must Sign In to post a response.
|
|
|
|