.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to add root element to XML in C#

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net
if i add xml in this message body , getting in a single line...that's y i put at below site Please open https://sites.google.com/site/narsareddy007/pesonal & then Open NewElement.txt file

View Complete Post

More Related Resource Links

XmlSerializer - how to define class to not generate attributes in root element?

Hi! I have simple class that I serialize to xml file: <?xml version="1.0" encoding="utf-8"?> <MyRootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Area="East">   <Products>     <SalesProduct Taxable="true">       <Name>Sofa</Name>     </SalesProduct>     <Product>       <Name>Television</Name>     </Product>   </Products> </MyRootElement> I don`t want have in xml file attributes xmlns:xsi and xmlns:xsd. How can I define class to not have these two attributes in xml file? I tried use XmlRoot attribute but there is no control for these two attributes. They are always generated. Regards

Root Element

Hi all, I decided to post in this forum as it doesn't directly relate to others...being a user-end question. I have a network of equally configured XP computers, and one Vista computer. For some reason, accessing certain ASP.NET sites on the Vista computer has just started getting server exceptions "Root element is missing". Normally I would write this off as a plain server-side error and wait for it to be fixed. However, the exception only occurs from one machine. All other machines load just fine. Caches are clear, computer rebooted, no malware or any non-default windows services running, etc. (Pure client/office machines)Any ASP.NET gurus know why this might be? Or how to fix it? Could it stem from an SSL cert/verification issue? (The error sites are using SSL).Thanks for your insight.

Root element is missing error AFTER changing the List permission


I have an Infopath form that submits the data onto a SharePoint list. Everything works if the user has 'view, insert, edit, delete' access to the list. However, we dont want them to be able to delete and view the item so we gave this user group only 'insert' access. After doing so, they get the following error message:

The following DataObject either cannot be created or cannot be initialized:
The query cannot be run for the following DataObject: NameOfList
InfoPath cannot run the specified query.
The SOAP response indicates that the error occurred on the server:

Server was unable to process request. ==> The root element is missing. 

Anyone know if there's another way to solve this without granting the user group full access to the List?  I'm not an admin, I just normally request what type of permission to set on our sharepoint sites. 

Thanks for the help

XML file - write attributes in root element


i have to write the following XML file using .net 2005.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

- <IMPORTFILE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ARC_Carrier_Import.xsd">

Root element is missing at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke



Environment: Win XP ServicePpack 3


                    VS 2008

   Can any one help me out for the below weird exception..

System.Exception: Root element is missing.System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Xml.XmlReader.MoveToContent()
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

   Also installed WSE 3.0,but still not resolved.


   Thanks in Advance..

UpdatePanel is not a known element - message when upgrading to 1.0 ajax


It worked on one of my old pages.  I change the web.config, renamed all the <asp.

On some aspx page it doesn't recognize the updatepanel.  It only does on one page.  If I create a new aspx page with a different name - then it works.

Should I just create a new web project ajax - then copy all my code into there?  Or is there a way to get those old pages to recognize the new ajax controls?

get value from xml element



i have this xml

<Field Name="Users_wff_AU" Type="FIELD_TYPE_STRING" MultiValue="True">
<Value No="1">xyz</Value>
<Value No="2">abcl</Value>
<Value No="3">xcc</Value>

i want to get the  xcc in string variable

Dim strwfUser As String = xNode.Item("Value").InnerText

Could not find default endpoint element that references contract 'CurrencyProxy.CurrencyServiceSoap



I created 2 projects in my solution:

  1. Classic asp.net web service (asmx)
  2. Class library project which references service
  3. web site project which references class library project
  4. Windows app project which references service.

Both projects were created in 3.5 framework and in Visual Studio 2008 Beta 2.

I added web service reference to Class library project. When it asked for namespace I typed "CurrencyProxy". Projects build ok, but when I run web app, Class library throws an error: Could not find default endpoint element that references contract 'CurrencyProxy.CurrencyServiceSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

I believe it has something to do with app.config in Class library project. Here is part from app.config:

<binding name="CurrencyServiceSoap" closeTimeout=

'element.className' is null or not an object



I just downloaded the project, compiled it and ran it right out of the box and when I put the mouse pointer over or remove the mouse pointer from either MenuItem in the menu demo, I generate this error:

'element.className' is null or not an object

It points to this javascript method:

updateClassName: function(operation, element, name, value) {
        this[operation + 'String'](
                function() {
                    return element.className;
                function(newValue) {
                    element.className = newValue;

Modify Menu adapter to show selected


Hey, I need some help modifying the menu adapter code to give child <ul> elements a class value indicating that the parent is selected. It should render like this:


< ul class="AspNet-Menu">
	< li class="AspNet-Menu-WithChildren  AspNet-Menu-ChildSelected">
		< a href="/rockit/admin/Default.aspx" class="AspNet-Menu-Link  AspNet-Menu-ChildSelected">
		< span>Mypage< /span>< /a>
			< ul class="AspNet-Sub AspNet-Sub-Selected">
				< li class="AspNet-Menu-Leaf  AspNet-Menu-Selected">
					< a href="/rockit/admin/Default2.aspx" class="AspNet-Menu-Link  AspNet-Menu-Selected">
					< span>Test< /span>< /a>
				< /li>
				< li class="AspNet-Menu-Leaf">
					< a href="/rockit/Default3.aspx" class="AspN

Debugging: Root Out Elusive Production Bugs with These Effective Techniques


Errors happen. But in production, error logs often provide little or no help in pinpointing the exact line of code in which the problem originates. You can't usually isolate the root cause by modifying code in a production environment because recreating the exact same environment is very difficult due to the large number of potential software and hardware configurations. This article provides some concrete steps you can take to get at the heart of the problems in your production code.

Matt Adamson

MSDN Magazine July 2005

Wrong root, absolute paths '~' don't work.


Hi guys,

I have some kind of strange problem. I use Visual Studio 2008 Standard Edition, and whenever I use ~ in links (like PostBackUrl = "~/Admin/AddProduct.aspx"),  ~ is translated into "C:\DocumentAndSettings\User\Desktop" instead of my application root. Of course I dont have any project on Desktop. It happens in every project I run , even in project from pendrive which works properly on other computers.

How can i solve this problem ? What and where should i change ? I will be very thankful for any help.


Add root xsi attributes to existing documents

I am looking for a way to perform a table update of an XML column containing strongly typed data. Recently, we modified our schema to include xmlns:xsi and xsi:schemaLocation. The thousands of documents already in the table, do not contain these new root element attributes, and I would like to add them. Sample old xml doc: <ROOT xmlns="http://www.xyz.com"><br/> <TAG>12345</TAG><br/> </ROOT>   Sample new xml doc: <ROOT xmlns="http://www.xyz.com"<br/> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br/> xsi:schemaLocation="http://www.xyzcom/schemas/A http://www.xyz.com/schemas/A/a.xsd"><br/> <TAG>12345</TAG><br/> </ROOT> Any thoughts or suggestions on how this might be accomplished?

XSD: Reading string in ROOT of XML

Hi all, I am making a import from XML to SQL. I have chosen to do this via a XSD file, but I have a problem with the ROOT file of the XMLXML:<Dogs bulkmode="0" xmlns="http://scheme01.isp.com">  <UnderDogs>    ...  </UnderDogs></Dogs>XSD:<xsd:element name="Dogs bulkmode="0" xmlns="http://scheme01.isp.com"" sql:is-constant="1">Unfortunately this does not work. If I (for testing) changes the first line of the XML to <Dogs>, (and corrects the XSD) it works like a charm.  It is not an option to change the XML file, so somehow I need to make the changes within my XSD. Does anyone have any suggestions?RegardsBirger Wilhelmsen

Schema :relatioship expected & constant/fixed element cannot have attributes

I try to bullkload data from xml file to SQL database ,but I cannot figure out the problem.Please anyone help me .I'd really appreciate. the XML file :  <?xml version="1.0" encoding="UTF-8"?> <root>        <!-- ????? -->        <common>               <!-- UploadDataCenterID???????????????? -->               <UploadDataCenterID>XXXXXX</UploadDataCenterID>               <CreateTime>YYYY-MM-DD HH:MM:SS</CreateTime>        </common>        <data>                 <BuildGroup id="XXXXXXXXXX">                        <BuildGroupBaseInfo operation="N|U">                             <F_BuildGroupName>?????</F_BuildGroupName>                             <F_GroupAliasName>???????</F_GroupAliasName>                             <F_GroupDesc><![CDATA[?????]]></F_GroupDesc>                      </BuildGroupBaseInfo>                      <BuildGroupRelaInfo operation="N|U">                             <F_BuildID>XXXXXXXXXX</F_BuildID>                      </BuildGroupRelaInfo>               </BuildGroup>        </data> </root> then the XSD :<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xs

How can I specify xsi:schemaLocation inside my path or root tag?

I am using: SELECT RecordCode, FieldToBeBlank, [Year] , [Month] FROM dbo.SomeTable FOR XML PATH('CustomRootName'), ELEMENTS XSINIL Which then returns:   <CustomRootName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <RecordCode>5</RecordCode> <FieldToBeBlank xsi:nil="true" /> <Year>2010</Year> <Month>8</Month> </CustomRootName>   However, I need to also include xsi:schemaLocation="blah BLAHV6.xsd" in that CustomRootName tag. How can I set it up so that it would read more like: < CustomRootName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="blah BLAHV6.xsd">       
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend