473,473 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Data at the root level is invalid. Line 1, position 1.

3 New Member
hi all ,
when m trying to validate my xml using xsd file it gives me the following error
"Data at the root level is invalid. Line 1, position 1"

i tried to open the XML file using IE and there are no errors and there are no blank space before the root element.the xml is created dynamically and it is send as a string to validate. the dynamically generated xml string is the following.

<?xml version="1.0" encoding="utf-8" ?>
<MessageEntity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Email retryattempts="1">
<Message>
<From>NotificationEmail</From>
<Recipients>
<Recipient recipientid="email@gmail.com" retryattempts="1" templateid="0" subject="email" />
</Recipients>
<Subject>email</Subject>
<Body>hi this is email body</Body>
<TemplateId>0</TemplateId>
</Message>
</Email>
<Sms retryattempts="0">
<Message>
<From>Notificationsms</From>
<Recipients>
<Recipient recipientid="9986267364" retryattempts="0" templateid="0" subject="SMS" />
</Recipients>
<Subject>SMS</Subject>
<Body>sms message</Body>
<TemplateId>0</TemplateId>
</Message>
</Sms>
</MessageEntity>


and the schema file is the following.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Notification">
<xs:complexType>
<xs:sequence>
<xs:element name="Email">
<xs:complexType>
<xs:sequence>
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="From" />
<xs:element name="Recipients">
<xs:complexType>
<xs:sequence>
<xs:element name="Recipient">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="recipientid" type="xs:string" use="required" />
<xs:attribute name="retryattempts" type="xs:string" use="required" />
<xs:attribute name="templateid" type="xs:string" use="required" />
<xs:attribute name="subject" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Subject" />
<xs:element name="Body" />
<xs:element name="TemplateId" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="retryattempts" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Sms">
<xs:complexType>
<xs:sequence>
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="From" />
<xs:element name="Recipients">
<xs:complexType>
<xs:sequence>
<xs:element name="Recipient">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="recipientid" type="xs:string" use="required" />
<xs:attribute name="retryattempts" type="xs:string" use="required" />
<xs:attribute name="templateid" type="xs:string" use="required" />
<xs:attribute name="subject" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Subject" />
<xs:element name="Body" />
<xs:element name="TemplateId" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="retryattempts" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


can anyone help me plz...
regards,
John
Aug 29 '07 #1
4 8149
MarkoKlacar
296 Recognized Expert Contributor
Hi,

you have to follow your XSD more carefully. Your file starts with the element <MessageEntity> whereas you XSD states that the first element should be <Notification>.

The following example will show you how to get started:

<Notification>
<Email>
<Message>
...
...
</Message>
</Email>
</Notification>

Follow the XSD, looks a bit strange in this case did you write it?, and everything should be ok.

Hope this helps.
Aug 29 '07 #2
johnsonkt
3 New Member
hi ,
thanks for the reply.

i tried on what u said.now my xsd looks

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MessageEntity">
<xs:complexType>
<xs:sequence>
<xs:element name="Email">
<xs:complexType>
<xs:sequence>
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="From" />
<xs:element name="Recipients">
<xs:complexType>
<xs:sequence>
<xs:element name="Recipient">
<xs:complexType>
<xs:attribute name="recipientid" type="xs:string" use="required" />
<xs:attribute name="retryattempts" type="xs:unsignedByte" use="required" />
<xs:attribute name="templateid" type="xs:unsignedByte" use="required" />
<xs:attribute name="subject" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Subject" />
<xs:element name="Body" />
<xs:element name="TemplateId" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="retryattempts" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Sms">
<xs:complexType>
<xs:sequence>
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="From" />
<xs:element name="Recipients">
<xs:complexType>
<xs:sequence>
<xs:element name="Recipient">
<xs:complexType>
<xs:attribute name="recipientid" type="xs:string" use="required" />
<xs:attribute name="retryattempts" type="xs:unsignedByte" use="required" />
<xs:attribute name="templateid" type="xs:unsignedByte" use="required" />
<xs:attribute name="subject" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Subject" />
<xs:element name="Body" />
<xs:element name="TemplateId" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="retryattempts" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

now the xml string and xsd matches.but still the same error. the xsd was created automatically by the visual studio 2005 on submitting the xml document.
Aug 29 '07 #3
MarkoKlacar
296 Recognized Expert Contributor
What does your XML-file look like now?

I don't know how much you know about XML and XSD but the idea is that the XSD is a description of how the XML-file must look, i.e how the elements have to be organized in what order etc.

Is the XML-file also auto-generated or are you the one writing it?
Auto generation is good, but you should only use it once you master the things you are working with.
Aug 30 '07 #4
jkmyoung
2,057 Recognized Expert Top Contributor
If you're generating this xml from a program, what class are you using to output the xml? You may be encountering an encoding problem.
Aug 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Korivo | last post by:
Im getting this error while trying to read a xml file that i receive from a POST heres the code: Dim MyXmlReader As XmlTextReader Dim strNodeResult As String Dim NodeType As XmlNodeType Dim...
1
by: Alan Wang | last post by:
Hi there, I got this message ("The data at the root level is invalid. Line 1, position 1.") when I moved the application from my workstation to Windows 2003 web server. But the wired thing the...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. Asset List is a long array of AssetIds. I declare it as: Dim AssetList(0) As Long AssetList(0) = 47288 Now, I pass an array of AssetIDs as long from here into the...
2
by: =?Utf-8?B?am1ncm8=?= | last post by:
I created a web service in visual studio 2003, tested it with a sample.xml file from a vendor we are using, and it worked exactly like it should. I depoloyed it to our server, created a project...
1
by: paulnamroud | last post by:
Hi all, I wrote a stored procedure with ms sql 2005 which returns a string parameter. This parameter contains differents xml elements and it's well formated. First, its works fine when i call...
1
by: ayemyat | last post by:
Hi All, I have a remoting service which consumes the web service in another server. I have the following exception throw by the web service. System.Xml.XmlException: The data at the root level...
2
by: Cirene | last post by:
My ASP.NET project builds fine (VS2008). I added a new web deployment project. When I try to build it I get: Data at the root level is invalid. Line1, position 1. (The file is web.config,...
3
by: Hamayun Khan | last post by:
Hi I get the following error Server Error in '/teachnetwork' Application. -------------------------------------------------------------------------------- Parser Error Description: An...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.