473,396 Members | 1,997 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,396 software developers and data experts.

Issues writing XSD file

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 8363
jkmyoung
2,057 Expert 2GB
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
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:normalizednormalizedString'. It was detected that 'xs:normalizednormalizedString' 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:normalizednormalizedString' 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 Expert 2GB
You probably mean 'xs:normalizedString' (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
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:normalizednormalizedString'. It was detected that 'xs:normalizednormalizedString' 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:normalizednormalizedString' 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
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 Expert 2GB
Less errors is not always better...

<xs:attribute name="date" type="xs:normalizedString"/>
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
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 Expert 2GB
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
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_letter' 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
jkmyoung
2,057 Expert 2GB
2 Things

1. If you're going to put elements inside a complex type, you need a sequence, choice, or all node.

2. attributes have to come after the sequence of elements in the complexType.
Sep 21 '10 #11

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

Similar topics

0
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...
0
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...
0
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...
1
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 ==...
1
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
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...
1
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
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...
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,...

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.