write xml file using xml control

Hi Guys,

Environment: asp.net 2.0 

Lang:vb.net 

 I am trying to create a xml file using xml control at rumtime. I have a asp:xml control with DocumentSource property set to xml file myFile.xml.

myFile.xml:

<myRoot>
          <EMPLOYEE>
               <FNAME></FNAME>
               <LNAME></LNAME>
               <DOB></DOB>
 </EMPLOYEE>
</myRoot>

following is the code to read the myFile.xml doc.

Dim rootElement As XmlElement
        Dim rootChild As XmlNodeList
        Dim curNode As XmlNode
        Dim childCnt As Integer
        Dim curNodeChilds As XmlNodeList
        Dim NodeElement As XmlNode
        Dim iLoop As Integer
        Dim itemExist As Integer = 0

 rootElement = myXml.Document.DocumentElement   //myXml is asp:xml control ID
        rootChild = rootElement.ChildNodes
        childCnt = rootChild.Count

        For iLoop = 0 To childCnt - 1
            curNode = rootChild.Item(iLoop)
            If curNode.Name = "EMPLOYEE" Then
                curNodeChilds = curNode.ChildNodes
                NodeElement = curNodeChilds.Item(1)
                If NodeElement.Value = fDocNum Then
                    itemExist = 1
                    Exit For
                End If
            End If
        Next

 'record not exist in the file then add
        If itemExist <> 1 Then
  ////

  HOW TO ADD DATA TO THE CONTROL

  ////
        End If

Please let me know how to data to the asp:xml control.

 

Thanks

Sham

0
sham
6/7/2007 7:32:40 PM
asp.net.xml-datasource 7181 articles. 0 followers. Follow

6 Replies
575 Views

Similar Articles

[PageSpeed] 18

Hi sham ,

From above code I think what you need is to dynamically set DataSource to XML control.

There are two approaches:

 1  Sets the XML document using a System.Xml.XmlDocument object.

       http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.xml.document.aspx

 2  Sets the XML document using a string.

     http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.xml.documentcontent.aspx


NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
6/11/2007 2:18:33 AM

Hi Young,

My requirement is, I read a xml file (just for format use only) and populate the xml document at runtime and bind this to xml web control. for eg: the xml file look like this

<EMPROOT>
   <EMP>
       <FNAME></FNAME>
      <LNAME></LNAME>
      <SAL></SAL>
   </EMP>
</EMPROOT>

At runtime, I would like to add 3 records without modifying the base file.

lastname1,firstname1,10.00
lastname2,firstname2,20.00
lastname3,firstname3,30.00

These records should be available in the memory. What would be the solution to make it work.

 Thanks

Sham

 

0
sham
6/11/2007 5:50:47 PM

Please try this to add more records:

    protected void Button1_Click(object sender, EventArgs e)
    {
        XmlDocument doc=new XmlDocument();

        doc = Xml1.Document;
        XmlElement emp = doc.CreateElement("emp");
        XmlElement firstName = doc.CreateElement("firstName");
        firstName.InnerText  = "firstname1";
        XmlElement lastName = doc.CreateElement("lastName");
        lastName.InnerText = "lastname1";
        XmlElement sale = doc.CreateElement("sale");
        sale.InnerText = "12";
        emp.AppendChild(firstName);
        emp.AppendChild(lastName);
        emp.AppendChild(sale);
        doc.ChildNodes[1].AppendChild(emp);
        Xml1.Document = doc;
        Xml1.DataBind();
    }

 
NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
6/12/2007 6:23:49 AM

Young, Thanks for your reply. I loop through and added 5 emp elements to the document object. But, my xml webcontrol displaying only the last (sale) element not all of them. You have any idea why it is not displaying all the element.

To make sure, I save the document to the fiilesystem. It created 5 records with fname, lname, sale elements.

Thanks

 

0
sham
6/15/2007 5:19:15 PM

You may specify XPath or XSLT to Xml ServerControl.

For the code in my previous post I have Xml control like this:

         <asp:Xml DocumentSource="test75.xml" ID="Xml1" runat="server">        
        </asp:Xml>

And It will display all added records.

Please post relevant if that can't help.Thanks.


NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
6/18/2007 3:56:24 AM

I created xslt file to display the records. Its working now.

Thanks for your help.

0
sham
6/18/2007 12:29:22 PM
Reply:

Similar Artilces:

How to write a xml file to another computer using path like this \\Server5\XML\XMLTest.xml?
Hi Guys,How can I write a xml file that read from a dataset to another computer in our network?something like this path "\\Server5\XML\XMLTest.xml"I am using below code to write xml file.----------------------------------------            // create a file name to write to.            string filename = "\\Server5\XML\XMLTest.xml";            // create the FileStream to write with.        &nb...

Problems writing to an XML file
I'm brand new to using XML (in fact this is my first project), so bear with me, I may need a little hand-holding. I'm trying to create a page which simply adds data to an existing xml file. Ultimately it will add the data from a form, but to keep things simple, I've been simply using pre-defined values. Originally I was able to get the script to write the xml exactly as I needed, however it would simply overwrite the existing file every time it was accessed. This is unacceptable, as it will be used to add data to one file, sort of like a mini database. So after much pain and gnashi...

XML Transform to 1 XML file to another XML File
Hello All  I am a novice programmer. I want to transform 1 xml file to another xml file. I am looking for a example code where user will select source xml file and create another xml file in different file with different fields with some default validation of parsing date and default values.  Can anyone help me or let me know any available source code in C#/ASP.Net?  Ms Disha I am assuming you know xslt, if not, you would have to go look at that.  But if you do, then this document will help you out http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=...

Error parsing XML control using external XML file.
I am trying to use a simple asp:XML control and the documentSource attribute is an external XML file. I get this error: URL is not a valid virtual path What is the solution for this?   Hi brucec, Please try loading remote xml into XmlDocument and bind it to server control: // Create the XmlReader object. XmlTextReader reader = new XmlTextReader("http://msdn.microsoft.com/rss.xml"); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close();  Please feel free to let us know if you have further problem.Thanks.NOTE:If yo...

XML in, XML out
Hi All (and a happy holiday to those that will get a break), I am trying to read in an XML file of addresses. I need to remove all the address data from the file where code =~ /^000/ (there are none in the example data below). I need to reproduce that data 'as is', so I need to honour the tag structure, although the order of the tags doesn't need to be honoured. I have been trying to use XML::Simple and I had a go with XML::Smart but I haven't been able to get the results I want. My best effort is below (with XML::Simple). There are a couple of differences ...

XMl to XML
Hello,   I retrieved an XML from the dataset which retrieves data from the table in the database. I need to present the data  in a different structure. Is XSLT the way or are there any other options. please let me know. Thanks!! Yes XSLT is a good choice to convert xml file to other forms. You can take a look at XSLT Tutorial.Sincerely,Young Fang...

Microsoft Chart control for .NET Framework about state management and serialization problem, it works OK with one XML file but fails with another XML file
I use Microsoft Chart control for .NET Framework , you can see details at http://blogs.msdn.com/alexgor/archive/2008/10/27/microsoft-chart-control-for-net-framework-released.aspx The Chart1 is load data from a xml and save to ViewStateData, so even if after I click Reload button, the chart1 still display OK! I'm very strange that the chart1 works well after click Reload button if it's loaded from Chart1.Serializer.Load(HttpContext.Current.Server.MapPath("~/Template/1.xml"));but chart1 don't display fter click Reload button if it's loaded from Chart1.Serializer.Loa...

Writing to XML using XML::Writer
Hi, Can anybody give me a simple code snippet which writes or modifies this xml ? =09 <my_list> <guy name=3D"SomeGuy"> <user>Tom</user> <date-of-birth>Aug 2006</date-of-birth> </guy> <guy name=3D"AnotherGuy"> <user>Dicken</user> <date-of-birth>Aug 2006</date-of-birth> =20 </guy> </my_list>=09 I want to read and write into this simple xml, basically changing the values or deleting them. After scanning...

Using extracted XML with XML-based controls
Hi I extract some data from a database and use "select" command with "For XML" in a SqlDataSource, so the data is in XML format. I have problem using these data with XML-based controls like TreeView control. How can I use this type of XML with XML-based controls. Regards Hi, You can follow those steps: 1. Use the ExecuteXmlReader method of the System.Data.SqlClient.SqlCommand class to load the results of SQL Extensible Markup Language (XML) queries from Microsoft SQL Server into a System.Xml.XmlReader object. http://msdn2.microsoft.com/en-us/library/system.da...

XML datasource from external website XML file
Hi all i need to extract some data into a page on my website, but the xml file is on different web server, not in our bunch, but out in the ether.is it possible to use this file as a datsource directly, or is there some security issue, and i have to grab it and use it locally...??? the file has been put somewhere it can be accessed with a web browseras this file changes on a daily basis, i would also like to automate the daily retrieval, i'm assuming this is something not too simple either. as you would need a service or something to fire up at a specific time each day?! any he...

using xml datasource with a dynamic xml output from a website
hi guys. need help regarding this problem. we're doing a project right now that gets the latest stocks info from a website. we're passing username, password, and a year into a querystring and the website will have an xml output. the problem is that the output looks something like this : http://www.info.net/xml/page.aspx?id=user&pass=23423&year=2006. i'm wondering how i could directly use this in the xmldatasource itself. any ideas?   Hi Use HttpWebRequest and HttpWebResponse class. You can get xml string as output then you can do whatever you want(deal with xmldatasour...

Getting text from an XML file using XML::Twig
--f46d044285f20c454904b338c7a6 Content-Type: text/plain; charset=ISO-8859-1 Dear Beginners List, My code is based on an example from the XML::Twig documentation. I want to capture the text of a couple elements that have descendant elements and put this text in separate variables (one for each element's text). The problem in the code example is that all the text of the lower elements is returned in a 'print'. So to illustrate: <title>text # I want this piece of text saved in one variable <subtitle>more text # and this pie...

Help needed on XML database . How to use insert , update etc operations on XML file used as database
Hi !!! I am using an xml file as my database . But I can't  do insert , update and delete ops !!! Some one please help me ...... Pleaseeee help !!!! Its urgent .....     Maybe you need XPath, take a look at:http://www.w3schools.com/xpath/default.asp  Welcome to my SQL/ASPNET forum for Chinese http://51up.org/bbs/forumdisplay.php?fid=38...

Xml schema to Xml file
Is it possible to convert xml schema to xml file.How can i do read&writexmlschema using a dataset with xml schema. I converted a xml file to xml schema in a web appliction project.Then what should be location of shema that i need to give for a dataset I mean dataset.readxmlscheme(server.mappath(??))   Please let me know I am new to this field     dataset.ReadXml(Server.MapPath("xml\ProductList.xml")) will read the xml as well as the schema of thexml file. no need to convert it into schema file while using dataset as it will automatically define the ...

Web resources about - write xml file using xml control - asp.net.xml-datasource

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Otway fire still out of control but no threat to Falls Festival
Firefighters are battling to contain an out-of-control Great Otway National Park fire ahead of an expected hot and windy weather spike on Christmas ...

Review: Sugr Cube, the cute wooden portable AirPlay speaker with gesture controls
... rarer, pretty ones even rarer and the Sugr Cube goes one step further in its bid to stand out from the crowd: it offers gesture-based control. ...

You can control this family’s Christmas lights over the Internet
... Horrible disaster waiting to happen? You be the judge. You've never met Ken or Rebecca-Ellen and you probably never will. But you can control ...

This is how Amazon is taking control of delivery – and taking it away from UPS
As Amazon searches for ways to speed up delivery, the company this year made big strides toward cutting out the middle man and establishing a ...

You can control this family's Christmas lights over the internet and the results are mesmerising
... as they see fit. Visitors are greeted with a live webcam of the Fairbanks, Alaska house — pictured above — as well as a bank of controls for ...

Afghan officials: Key district besieged by Taliban still under state control
"Taliban rumors that they have captured the district are not true," says local official trapped for 3 days before government reinforcements arrived ...

Fox 'News' Blabbers Outraged Over 'Liberal' NBA Gun-Control Ad
It seems pretty political to one of Outnumbered's hosts, Andrea Tantaros, that the NBA would dare make an ad sponsored by gunsense advocate, ...

NRA: 6.3 Million Concealed Carry Permit Holders Affected By Virginia Gun Control Move
The National Rifle Association says 6.3 million concealed carry permit holders will be affected by Virginia’s Democrat Attorney General’s move ...

Secret Skills For Success: Give Up The Idea Of Control
There are plenty of job titles in organizations which include the term controller; financial controller, production controller...But they aren't ...

Resources last updated: 12/26/2015 8:49:15 PM