473,582 Members | 3,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issues writing XSD file

9 New Member
Learning XML and need some help.
I have am xml file and I have want to create an xsd file for it.
I have written my file, but am experiencing errors when trying to validate the xml to my xsd.
Any pointing in the right direction you can give would be appreciated.

XML file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <letter date="2005/1/1"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:noNamespaceSchemaLocation="http://some-where letter.xsd">
  5.  
  6. <to>
  7. <first>smith</first>
  8. <last>Lee</last>
  9. </to>
  10. <from>
  11. <first>Sylvie</first>
  12. <middle>S.</middle>
  13. </from>
  14. <title>Example</title>
  15. <msg>
  16. <paragraph>
  17. I have a question.
  18. <paragraph>
  19. Can you infer an XML Schema?
  20. </paragraph>
  21. </paragraph>
  22. </msg>
  23.  
  24. </letter>
  25.  
My XSD file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  3. <xs:element name="letter">
  4. </xs:element>
  5. <xs:complexType>
  6. <xs:element name="to" type="xs:normalizednormalizedString"/>
  7. <xs:element name="from" type="xs:normalizedString"/>
  8. <xs:element name="heading" type="xs:normalizedString"/>
  9. <xs:element name="body" type="xs:normalizedString"/>
  10. </xs:complexType>
  11. <xs:attribute>
  12. <xs:attribute name="last" type="xs:normalizedString"/>
  13. <xs:attribute name="first" type="xs:normalizedString"/>
  14. <xs:attribute name="middle" type="xs:normalizedString"/>
  15. <xs:attribute name="title" type="xs:normalizedString"/>
  16. <xs:attribute name="msg" type="xs:normalizedString"/>
  17. <xs:attribute name="paragraph" type="xs:normalizedString"/>
  18. </xs:attribute>
  19. </xs:schema>
  20.  
Here are the errors I am getting:

Ln 8 Col 64 - s4s-elt-invalid-content.1: The content of 'null' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
Ln 7 Col 18 - s4s-att-must-appear: Attribute 'name' must appear in element 'complexType'.
Ln 13 Col 15 - s4s-att-must-appear: Attribute 'name' must appear in element 'attribute'.
Ln 14 Col 58 - s4s-elt-must-match.1: The content of '(no name)' must match (annotation?, (simpleType?)). A problem was found starting at: attribute.
Sep 15 '10 #1
10 8378
jkmyoung
2,057 Recognized Expert Top Contributor
Your formation of schema doesn't fit standards. See this example for where to place your elements and attributes within a complexType:
Expand|Select|Wrap|Line Numbers
  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  2.     <xs:element name="beer">
  3.         <xs:complexType>
  4.             <xs:sequence>
  5.                 <xs:element name="a"/>
  6.                 <xs:element name="b"/>
  7.             </xs:sequence>
  8.             <xs:attribute name="attb"/>
  9.             <xs:attribute name="atta"/>
  10.         </xs:complexType>
  11.     </xs:element>
  12. </xs:schema>
  13.  
Sep 17 '10 #2
stephen1313
9 New Member
Thanks for your reply.
Here is what I have now.
My XSD file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  3. <xs:element name="letter">
  4.     <xs:complexType>
  5.     <xs:sequence>
  6.     <xs:element name="to" type="xs:normalizednormalizedString"/>
  7.       <xs:element name="from" type="xs:normalizedString"/>
  8.     <xs:element name="title" type="xs:normalizedString"/>
  9.     <xs:element name="msg" type="xs:normalizedString"/>
  10.     </xs:sequence>
  11.     <xs:attribute name="date" type="xs:normalizedString"/>
  12.       <xs:attribute name="last" type="xs:normalizedString"/>
  13.     <xs:attribute name="first" type="xs:normalizedString"/>
  14.     <xs:attribute name="middle" type="xs:normalizedString"/>
  15.     <xs:attribute name="paragraph" type="xs:normalizedString"/>
  16.     </xs:complexType>        
  17. </xs:element>
  18. </xs:schema>
My errors:
Ln 6 Col 62 - src-resolve.4.2: Error resolving component 'xs:normalizedn ormalizedString '. It was detected that 'xs:normalizedn ormalizedString ' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:///C:/XML/lettersl.xsd'. If this is the incorrect namespace, perhaps the prefix of 'xs:normalizedn ormalizedString ' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///C:/XML/lettersl.xsd'.
Ln 13 Col 10 - cvc-type.3.1.2: Element 'from' is a simple type, so it must have no element information item [children].
Ln 22 Col 9 - cvc-type.3.1.2: Element 'msg' is a simple type, so it must have no element information item [children].
Sep 17 '10 #3
jkmyoung
2,057 Recognized Expert Top Contributor
You probably mean 'xs:normalizedS tring' (one normalized)

Your from and msg nodes are actually a complex element containing other elements. eg 'from' from your code:
Expand|Select|Wrap|Line Numbers
  1. <from> 
  2.   <first>Sylvie</first> 
  3.   <middle>S.</middle> 
  4. </from> 
  5.  
Put in another element definition inside much like your first one.
Example of nesting element:
Expand|Select|Wrap|Line Numbers
  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
  2.     <xs:element name="beer"> 
  3.         <xs:complexType> 
  4.             <xs:sequence> 
  5.                 <xs:element name="a">
  6.                 <xs:complexType>
  7.                   <xs:sequence>
  8.                     <xs:element name="a_child1"/>                      
  9.                                   <xs:element name="a_child2"/>                      
  10.                   </xs:sequence>
  11.                 </xs:complexType>
  12.                 </xs:element> 
  13.                 <xs:element name="b"/> 
  14.             </xs:sequence> 
  15.             <xs:attribute name="attb"/> 
  16.             <xs:attribute name="atta"/> 
  17.         </xs:complexType> 
  18.     </xs:element> 
  19. </xs:schema> 
Example of using reference instead:
Expand|Select|Wrap|Line Numbers
  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  2.     <xs:element name="beer">
  3.         <xs:complexType>
  4.             <xs:sequence>
  5.                 <xs:element ref="a"/>
  6.                 <xs:element name="b"/>
  7.             </xs:sequence>
  8.             <xs:attribute name="attb"/>
  9.             <xs:attribute name="atta"/>
  10.         </xs:complexType>
  11.     </xs:element>
  12.     <xs:element name="a">
  13.         <xs:complexType>
  14.             <xs:sequence>
  15.                 <xs:element name="a_child1"/>
  16.                 <xs:element name="a_child2"/>
  17.             </xs:sequence>
  18.         </xs:complexType>
  19.     </xs:element>
  20. </xs:schema>

Other option, change your source xml to attributes:
First and middle are elements not attributes. An equivalent with attributes might be:
<from first="Sylivie" middle="S."/>
Sep 17 '10 #4
stephen1313
9 New Member
Ok, here is my code now:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  3. <xs:element name="letter">
  4. <xs:complexType>
  5.     <xs:sequence>
  6.         <xs:element name="to" type="xs:normalizednormalizedString"/>
  7.                 <xs:element name="first" type="xs:normalizedString"/>
  8.                 <xs:element name="last" type="xs:normalizedString"/>
  9.                 </xs:sequence>
  10.                 </xs:complexType>
  11.     <xs:complexType>
  12.     <xs:sequence>
  13.         <xs:element name="from" type="xs:normalizedString"/>
  14.                 <xs:element name="first" type="xs:normalizedString"/>
  15.                   <xs:element name="middle" type="xs:normalizedString"/>
  16.                   </xs:sequence>
  17.                   </xs:complexType>
  18.       <xs:complexType>
  19.       <xs:sequence>
  20.           <xs:element name="title" type="xs:normalizedString"/>
  21.         <xs:element name="msg" type="xs:normalizedString"/>
  22.         <xs:element name="paragraph" type="xs:normalizedString"/>
  23.                 </xs:sequence>
  24.                   </xs:complexType>        
  25. </xs:element>
  26. </xs:schema>
Here are my errors now:
Ln 11 Col 18 - s4s-elt-must-match.1: The content of 'letter' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: complexType.
Ln 6 Col 63 - src-resolve.4.2: Error resolving component 'xs:normalizedn ormalizedString '. It was detected that 'xs:normalizedn ormalizedString ' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:///C:/XML/lettersl.xsd'. If this is the incorrect namespace, perhaps the prefix of 'xs:normalizedn ormalizedString ' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///C:/XML/lettersl.xsd'.
Ln 4 Col 61 - cvc-complex-type.3.2.2: Attribute 'date' is not allowed to appear in element 'letter'.
Ln 10 Col 9 - cvc-complex-type.2.4.a: Invalid content was found starting with element 'from'. One of '{first}' is expected.
Sep 17 '10 #5
stephen1313
9 New Member
Here is an update for those of you helping me out:
I have updated my code to the following:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  3.  
  4.  
  5. <xs:element name="letter">
  6. <xs:attribute name="date" type="xs:normalizedString"/>
  7. <xs:complexType>
  8. <xs:sequence>
  9. <xs:element name="to" type="xs:normalizednormalizedString"/>
  10. <xs:element name="first" type="xs:normalizedString"/>
  11. <xs:element name="last" type="xs:normalizedString"/>
  12. </xs:sequence>
  13. </xs:complexType>
  14. <xs:complexType>
  15. <xs:sequence>
  16. <xs:element name="from" type="xs:normalizedString"/>
  17. <xs:element name="first" type="xs:normalizedString"/>
  18. <xs:element name="middle" type="xs:normalizedString"/>
  19. </xs:sequence>
  20. </xs:complexType>
  21. <xs:complexType>
  22. <xs:sequence>
  23. <xs:element name="title" type="xs:normalizedString"/>
  24. <xs:element name="msg" type="xs:normalizedString"/>
  25. <xs:element name="paragraph" type="xs:normalizedString"/>
  26. </xs:sequence>
  27. </xs:complexType>
  28.  
  29. </xs:element>
  30. </xs:schema>
Now I am down to only 1 error on validation of my XML file:
Ln 6 Col 56 - s4s-elt-must-match.1: The content of 'letter' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: attribute.
Sep 17 '10 #6
jkmyoung
2,057 Recognized Expert Top Contributor
Less errors is not always better...

<xs:attribute name="date" type="xs:normal izedString"/>
Should be inside the complexType.

Have you changed your source file at all? Your 'from' element is currently set to a simple element as opposed to a complex one.
Sep 17 '10 #7
stephen1313
9 New Member
Editing the XML file is not an option. I have to make my XSD file conform to the XML.
I did move the date attribute as you instructed.
I am still getting this error:
Ln 6 Col 56 - s4s-elt-must-match.1: The content of 'letter' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: attribute.

Would I be better off using ANY rather than complexType?
Sep 17 '10 #8
jkmyoung
2,057 Recognized Expert Top Contributor
The attribute still has to be moved inside the complexType.
Pseudo (sorry, in a bit of a rush)
Expand|Select|Wrap|Line Numbers
  1. <element>
  2.   <complexType>
  3.     other elements
  4.     <attribute/> put this here. 
  5.   </complexType>
  6. </element>
No, if you used any, there's no real point in having a schema. Almost anything would validate.
Sep 17 '10 #9
stephen1313
9 New Member
Thanks for your help.
I think I am close to having this done.
Here is my code now:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  3. <xs:element name="letter">
  4.     <xs:complexType>
  5.         <xs:attribute name="date" type="xs:string"/>
  6.         <xs:element name="to" type="xs:normalizednormalizedString"/>
  7.                 <xs:complexType>
  8.                     <xs:attribute name="first" type="xs:normalizedString"/>
  9.                     <xs:attribute name="last" type="xs:normalizedString"/>
  10.                     </xs:complexType>
  11.     <xs:complexType>
  12.         <xs:element name="from" type="xs:normalizedString"/>
  13.                     <xs:attribute name="first" type="xs:normalizedString"/>
  14.                       <xs:attribute name="middle" type="xs:normalizedString"/>
  15.                       </xs:complexType>
  16.       <xs:complexType>
  17.           <xs:element name="title" type="xs:string"/>
  18.         <xs:element name="msg" type="xs:string"/>
  19.             <xs:attribute name="paragraph" type="xs:string"/>
  20.                      </xs:complexType>        
  21. </xs:complexType>
  22. </xs:element>
  23. </xs:schema>
  24.  
Here is my error now:
Ln 6 Col 63 - s4s-elt-invalid-content.1: The content of '#AnonType_lett er' is invalid. Element 'element' is invalid, misplaced, or occurs too often.

If you can help, I would really appreciate it. I have to get this done so I can move on to other content.
Sep 18 '10 #10

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

Similar topics

0
1128
by: Michael George Lerner | last post by:
I was helping someone debug his code today .. it worked fine on Linux, but gave a strange error message on Windows. Here's the snippet that goes wrong in Python 2.2 under Windows (it also happens under 2.3a1 under Windows and Enthought's 2.3.3, so I think it's pretty generic) .. : >>> os.remove('test.txt') >>> f = file('test.txt','a+')...
0
6110
by: JC | last post by:
I am using Mysql version: 4.0.18-max-log and trying to populate a database from a text file using source option from inside the mysql environment. The population run OK but when creating the indexes i get < ----- ERROR -------------> Query OK, 1 row affected (0.00 sec)
0
2553
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming...
1
2363
by: Glenn Coyle | last post by:
Hi I am having trouble writing the file path of a image to the database,also for some reason it is not uploading the images, anyone have any ideas? the code is below: if($_POST == 'Submit') {
1
2511
by: Debabrata Jana | last post by:
Hi all, I use solaris 5.8 OS. I have three OS user : 1) orac9ias 2)oracle9i 3)backup I use the following command to export a oracle export backup (I use oracle9i release 1):
4
1795
by: FingerDemon | last post by:
I'm guessing I'm missing something obvious here, but I have searched around and re-read my Python books and references on simple file writing and I can't see the answer. I am running this in Windows XP in IDLE. I have some simple code I wrote to open a large log file with 39 extra characters starting each line that I want to strip out. Then I...
1
2135
by: Mr fahad | last post by:
#include <stdio.h> #include <conio.h> void main (void) { char ch; FILE *fp; fp=fopen ("fahd.txt","w"); while (ch=fgetc( )!='\r') fputc (ch,fp); fclose (fp);
4
3670
by: Jim | last post by:
Hi There, I'm trying to read a file character by character. When I write the file out, there is one extra character which shows on the screen as a solid circle with a small question mark in the middle. Here is what I have: infile = fopen("encrypted.txt", "r"); outfile = fopen("plain.txt", "w");
1
1150
by: =?Utf-8?B?Y2phbXBz?= | last post by:
I have HL-DT-ST RW/DVD GCC-4240N. It seems to be a problem though with either the cd rom drive or the operating system because whatever CD I put in it does not recognize as a CDR or a CDRW eventhough it does read from them. It tells me that there is no disc in the drive and to please insert a writable CD into the drive. I am running a DELL...
0
7809
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8183
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6569
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1413
muto222
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.