C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Create XML File


Posted Date: 04 Dec 2008      Posted By: Ashokkumar      Member Level: Gold     Points: 1   Responses: 5



Dear All ,

I am new to XML , i working in Asp.net2.0 with C# project, i want to use Adrotator Control, i worked the sample Code for XML in Static input; How can i create the XML file in load from database; i'll try to create the File , But it comes
<table>
<td>
<database filed>data</datbase>
<database filed> data</databde>
</td>
<td>
...
..
</td>
</table>

But in Adrotator XML files are
<advertisement>
<ad>
..
..
</ad>
<ad>
..
..
</ad>
How can i Modified the XML file , Help me, it's Urgent

Thanks





Responses

Author: Patel    04 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

To create XMl File from Database

protected void cmdDataSetToXml_Click(object sender, EventArgs e)
{
string connectionString =
WebConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
string SQL = "SELECT * FROM authors WHERE city='Oakland'";

// Create the ADO.NET objects.
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(SQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet("AuthorsDataSet");

// Retrieve the data.
con.Open();
adapter.Fill(ds, "AuthorsTable");
con.Close();

// Create the XmlDataDocument that wraps this DataSet.
XmlDataDocument dataDoc = new XmlDataDocument(ds);

// Display the XML data (with the help of an XSLT) in the XML web control.
XmlControl.XPathNavigator = dataDoc.CreateNavigator();
XmlControl.TransformSource = Request.PhysicalApplicationPath + @"\App_Data\authors.xsl";

}


protected void cmdXmlToDataSet_Click(object sender, EventArgs e)
{
XmlDataDocument dataDoc = new XmlDataDocument();

// Set the schema and retrieve the data.
dataDoc.DataSet.ReadXmlSchema(Request.PhysicalApplicationPath +
@"\App_Data\SuperProProductList.xsd");
dataDoc.Load(Request.PhysicalApplicationPath + @"\App_Data\SuperProProductList.xml");

// Display the retrieved data.
gridData.DataSource = dataDoc.DataSet;
gridData.DataBind();
}



Author: Deepika Haridas    04 Dec 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 6

Hi,

// XML CODE THAT AS THE DETAILS ABOUT THE ADS
<Advertisements>
<Ad>
<ImageUrl>D:\Viv_B-Practice\AdRotator_VT\www.asp.net.gif</ImageUrl>
<NavigateUrl>http://www.asp.net</NavigateUrl>
<AlternateText>ASP.NET Logo</AlternateText>
<Keyword>A</Keyword>
<Impressions>Technology</Impressions>
<Caption>This is the caption for Ad#1</Caption>
</Ad>

<Ad>
<ImageUrl>D:\Viv_B-Practice\AdRotator_VT\www.sulekha.com.gif</ImageUrl>
<NavigateUrl>http://www.sulekha.net</NavigateUrl>
<AlternateText>www.Sulekha.net</AlternateText>
<Keyword>S</Keyword>
<Impressions>Web Site</Impressions>
<Caption>This is the caption for Ad#2</Caption>
</Ad>

<Ad>
<ImageUrl>D:\Viv_B-Practice\AdRotator_VT\FlashFile.swf</ImageUrl>
<NavigateUrl>AdRotator.aspx?ad=Widgets
&target=http://msdn.microsoft.com/widgets/</NavigateUrl>
<AlternateText>www.neostream.net</AlternateText>
<Keyword>S</Keyword>
<Impressions>Flash Site</Impressions>
<Caption>This is the caption for Ad#2</Caption>
</Ad>
</Advertisements>

.aspx page

<asp:AdRotator id="controlName" runat="server"
AdvertisementFile="ads.xml" Target="_self">
</asp:AdRotator>

code behind page

// Create an AdRotator control.
AdRotator rotator = new AdRotator();

// Set the control's properties.
rotator.AdvertisementFile = "AdRotatorFiles.xml";

// Add the control to the Controls collection of a
// PlaceHolder control.
PlaceHolder1.Controls.Add(rotator);



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: Rajendra    04 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 0

Create a dataset. And call Ds.getxml()

---



Author: Durga Prasad    05 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

using System.Xml;

void WriteXML()
{
try
{
//pick whatever filename with .xml extension
string filename = "XML"+DateTime.Now.Day + ".xml";

XmlDocument xmlDoc = new XmlDocument();

try
{
xmlDoc.Load(filename);
}
catch(System.IO.FileNotFoundException)
{
//if file is not found, create a new xml file
XmlTextWriter xmlWriter = new XmlTextWriter(filename, System.Text.Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
xmlWriter.WriteStartElement("Root");
//If WriteProcessingInstruction is used as above,
//Do not use WriteEndElement() here
//xmlWriter.WriteEndElement();
//it will cause the <Root></Root> to be <Root />
xmlWriter.Close();
xmlDoc.Load(filename);
}
XmlNode root = xmlDoc.DocumentElement;
XmlElement childNode = xmlDoc.CreateElement("childNode");
XmlElement childNode2 = xmlDoc.CreateElement("SecondChildNode");
XmlText textNode = xmlDoc.CreateTextNode("hello");
textNode.Value = "hello, world";

root.AppendChild(childNode);
childNode.AppendChild(childNode2);
childNode2.SetAttribute("Name", "Value");
childNode2.AppendChild(textNode);

textNode.Value = "replacing hello world";
xmlDoc.Save(filename);
}
catch(Exception ex)
{
WriteError(ex.ToString());
}
}

void WriteError(string str)
{
outputBox.Text = str;
}
------------------------

protected void LoadXmlIntoList()
{
DataSet ds = LoadDatasetFromXml("Persons.xml");

if (ds.Tables.Count > 0)
this.listViewDataSet.SetObjects(ds.Tables[0].Rows);
}
protected DataSet LoadDatasetFromXml(string fileName)
{
DataSet ds = new DataSet();
FileStream fs = null;
try {
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
} catch (Exception e) {
MessageBox.Show(e.ToString());
} finally {
if (fs != null)
fs.Close();
}

return ds;
}



Author: puneet malviya    05 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 4

Hi........


<Advertisements>
<Ad>
<ImageUrl>~/IMAGE/Tiger.jpg</ImageUrl>
<TargetUrl>http://www.client1.com</TargetUrl>
<Impression>1</Impression>
</Ad>
<Ad>
<ImageUrl>~/IMAGE/Tiger1.jpg</ImageUrl>
<TargetUrl>http://www.client1.com</TargetUrl>
<Impression>1</Impression>
</Ad>
<Ad>
<ImageUrl>~/IMAGE/Tiger2.jpg</ImageUrl>
<TargetUrl>http://www.client1.com</TargetUrl>
<Impression>1</Impression>
</Ad>
<Ad>
<ImageUrl>~/IMAGE/Tiger3.jpg</ImageUrl>
<TargetUrl>http://www.client1.com</TargetUrl>
<Impression>1</Impression>
</Ad>
</Advertisements>

write this on Xml File For Adrotator



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : menu item problem
Previous : Fill dropdownlist
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use