473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem Loading XML

Hi,

I have created One Xml Structure using the following Code.

XmlDocument xd = new XmlDocument();
xd.LoadXml("<IPR><Test>123</Test><GSD>GSDINDIA</GSD></IPR>");
XmlElement xElem = xd.CreateElement("Personalization");
xElem.InnerXml = "<?xml version=\"1.0\"?><WrapClass
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><obj
xsi:type=\"DefinePersonalization\"><Personalizatio nName>RestrictAccess</PersonalizationName><UserGroup><anyType
xsi:type=\"xsd:string\">administrator</anyType><anyType
xsi:type=\"xsd:string\">vinoth</anyType></UserGroup></obj></WrapClass>";
xd.DocumentElement.AppendChild(xElem);
Later i want to Load this XML. When i load this XML using LoadXml
method its giving the following error.

Error :

Unexpected XML declaration. The XML declaration must be the first node
in the document, and no white space characters are allowed to appear
before it.

How can i solve this problem? If anybody knows the solution please let
me know to solve it.
Thanks,
Vinoth

Nov 17 '05 #1
5 7042
You should remove <?xml version=\"1.0\"?> from the xElem.InnerXml.

Nov 17 '05 #2
Is there anyother solution without removing this Line.

Thanks,
Vinoth

Nov 17 '05 #3
No, such declaration should be at the very beginning of the document.
If you want it, you should add it to xd.LoadXml.

xd.LoadXml("<?xml
version=\"1.0\"?><IPR><Test>123</Test><GSD>GSDINDIA</GSD></IPR>");

Nov 17 '05 #4
I guess you want to import a xml document into another xml document,
right?
If so, load 2 XmlDocument separately, then import a
XmlDocument.DocumentElement into the other XmlDocument using
XmlDocument.ImportNode, then append the imported node using AppendChild
method..

Nov 17 '05 #5
Hi,

XML declaration must be outside document element node and should be first
line of the xml. You cannot add xml declaration inside any other node. You
need to change your xElem.InnerXml value.

Mihir Solanki
http://www.mihirsolanki.com
Hi,

I have created One Xml Structure using the following Code.

XmlDocument xd = new XmlDocument();
xd.LoadXml("<IPR><Test>123</Test><GSD>GSDINDIA</GSD></IPR>");
XmlElement xElem = xd.CreateElement("Personalization");
xElem.InnerXml = "<?xml version=\"1.0\"?><WrapClass
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><obj
xsi:type=\"DefinePersonalization\"><Personalizatio nName>RestrictAccess
</PersonalizationName><UserGroup><anyType
xsi:type=\"xsd:string\">administrator</anyType><anyType
xsi:type=\"xsd:string\">vinoth</anyType></UserGroup></obj></WrapClass>
";
xd.DocumentElement.AppendChild(xElem);
Later i want to Load this XML. When i load this XML using LoadXml
method its giving the following error.

Error :

Unexpected XML declaration. The XML declaration must be the first node
in the document, and no white space characters are allowed to appear
before it.

How can i solve this problem? If anybody knows the solution please let
me know to solve it.

Thanks,
Vinoth

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael | last post by:
Greetings, I have a DLL which I am loading using Systm.loadLibrary(). I have put the DLL in a directory that is include in the PATH environment variable but I still get Unsatisfied Link Error. ...
1
by: Umashankar | last post by:
Dear Gurus, I am using listview control in a asp page to populate some database results.In some machines (which is having only OS and no other softwares installed) this control is not loading....
1
by: Nomad | last post by:
I'm trying to load an XML document into the DOM using the ActiveXObject I've succeeded in doing this on one machine. Which shouldn't becaus I've checked for the ActiveXObject and it doesn't...
1
by: Tom Vukovich | last post by:
I'm having a problem loading an xmldocument from the web. The xml i wish to bring into the application is generated from a request to an ASP page. The following code does not work. ...
2
by: NGM | last post by:
Hello All I have a unmanaged C++ DLL, which has been wrapped up with a manged C++ DLL. When i refer to this managed DLL in Windows form based applications it works out fine. But when i refer to...
0
by: Oenone | last post by:
I have created a number of "plug-in" DLLs for my ASP.NET application which are dynamically loaded at run-time. This is done by locating the DLL file on disk and loading it using the...
5
by: Pete Marsh | last post by:
Wondering if anyone can recomend some sample code for dynamically loading the GD module. I have tried setting the extension dir in php.ini, and loading the GD module from there when apache is...
6
by: Shigun | last post by:
On a website I am working on I am trying to load another page into a div on the the page the user does his work from. What I have works correctly in FireFox, but not in IE. I've rummaged Google for...
0
by: ndedhia1 | last post by:
I am having trouble loading a property file and keep getting this error when running my shell script that loads and runs my jar files, etc: no property file loaded, using defaults......
1
ifedi
by: ifedi | last post by:
Hi guys, Kindly spare a moment to look at this page: http://gottkann.com Most of the page content is designed to be loaded by AJAX (mostly jQuery .post and .get) on clicking the menu links on top...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.