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

DTD validation fails depending on format

I am using a DTD file to validate XML files. The format I would like to use defines an 'item' as:
Expand|Select|Wrap|Line Numbers
  1. <item item_idx="1" item_type="ExactNumber" content=".68" hint="Correlation does not equal causation."/>
However, this seems to fail to validate. It successfully validates if I define 'item' as:
Expand|Select|Wrap|Line Numbers
  1. <item>
  2.         <item_idx>1</item_idx>
  3.     <item_type>ExactNumber</item_type>
  4.     <content>.68</content>
  5.     <hint>Correlation does not equal causation</hint>
  6. </item>
Do I need to define the DTD in a different way in order to use the first style? Or do I need to use a different XML schema?

Thanks for any help, below is the DTD file and the two examples in full.

DTD:
<!ELEMENT problem-set (problem+)>
<!ELEMENT problem (problem_idx, item+)>
<!ELEMENT problem_idx (#PCDATA)>
<!ELEMENT item (item_idx, item_type, content, hint)>
<!ELEMENT item_idx (#PCDATA)>
<!ELEMENT item_type (#PCDATA)>
<!ELEMENT content (#PCDATA)>
<!ELEMENT hint (#PCDATA)>

XMLExample1:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE problem-set SYSTEM "http://macalester.edu/~whart/XMLSchema.dtd">
  3. <problem-set>
  4.     <problem>
  5.         <problem_idx>ProblemIndex1</problem_idx>
  6.         <item>
  7.             <item_idx>1</item_idx>
  8.             <item_type>ExactNumber</item_type>
  9.             <content>.68</content>
  10.             <hint>Correlation does not equal causation</hint>
  11.         </item>
  12.         <item>
  13.             <item_idx>2</item_idx>
  14.             <item_type>ExactNumber</item_type>
  15.             <content>.95</content>
  16.             <hint>Causation equals correlation</hint>
  17.         </item>
  18.         <item>
  19.             <item_idx>3</item_idx>
  20.             <item_type>FreeText</item_type>
  21.             <content></content>
  22.             <hint>How much is a standard deviation?</hint>
  23.         </item>
  24.     </problem>
  25.     <problem>
  26.         <problem_idx>ProblemIndex2</problem_idx>
  27.         <item>
  28.             <item_idx>1</item_idx>
  29.             <item_type>TrueOrFalse</item_type>
  30.             <content>true</content>
  31.             <hint>The truth lies in your mind.</hint>
  32.         </item>
  33.     </problem>
  34.     <problem>
  35.         <problem_idx>ProblemIndex3</problem_idx>
  36.         <item>
  37.             <item_idx>a</item_idx>
  38.             <item_type>MC</item_type>
  39.             <content>dublin</content>
  40.             <hint>Think green</hint>
  41.         </item>
  42.     </problem>
  43. </problem-set>

XMLExample2:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2.     <problem-set>
  3.         <problem>
  4.             <problem_idx>ProblemIndex1</problem_idx>
  5.             <item item_idx="1" item_type="ExactNumber" content=".68" hint="Correlation does not equal causation."></item>
  6.             <item item_idx="2" item_type="ExactNumber" content=".95" hint="Causation equals correlation."></item>
  7.             <item item_idx="3" item_type="FreeText" content="" hint="How much is a standard deviation?"></item>
  8.         </problem>
  9.         <problem>
  10.             <problem_idx>ProblemIndex2</problem_idx>
  11.             <item item_idx="1" item_type="TrueOrFalse" content="true" hint="The truth lies in your mind."></item>
  12.         </problem>
  13.         <problem>
  14.             <problem_idx>ProblemIndex3</problem_idx>
  15.             <item item_idx="a" item_type="MC" content="dublin" hint="Think green."></item>
  16.         </problem>
  17.     </problem-set>
Jun 12 '07 #1
3 1332
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN...

Try this way:
<!ELEMENT problem-set (problem+)>
<!ELEMENT problem (problem_idx, item+)>
<!ELEMENT problem_idx (#PCDATA)>
<!ELEMENT item EMPTY>
<!ATTLIST item item_idx CDATA #REQUIRED>
<!ATTLIST item item_type CDATA #REQUIRED>
<!ATTLIST item content CDATA #REQUIRED>
<!ATTLIST item hint CDATA #REQUIRED>

For more help, see this link.
Jun 13 '07 #2
Ah okay, that makes sense. Thank you very much Dorin!
Jun 13 '07 #3
dorinbogdan
839 Expert 512MB
You're welcome.
God bless you,
Dorin.
Jun 14 '07 #4

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

Similar topics

6
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to...
0
by: Brian Conway | last post by:
I am having some validation and insertion problems. I am using a date picker that takes the selected date and puts it to ("dd-MMM-yyyy") format, as this was the only format that Oracle would...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
12
by: Diego | last post by:
Can I validate (possibly with a compare validator) a Date entered by the user based upon his regional settings? I.e. if a user is american the format would be mm/dd/yyyy, if brittish dd/mm/yyyy...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.