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

XML Element Content

8
Hi there, I'm new to writing XML (just a couple of weeks old) so please bear with me.

I was wondering when it would be the right time to use PCDATA in the DTD. I think there are another two data types? CDATA and ANY?

It says on this website that the difference between the two DATA ones is for parsing and I'm sure sure if in this context that thats what I'd like to do.

This is what I've got at the moment:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE inventory [
  4.     <!ELEMENT inventory (vehicle?)>
  5.     <!ELEMENT vehicle (make, model, km, descr?, photo+)>
  6.     <!ELEMENT make (#PCDATA)>
  7.     <!ELEMENT model (#PCDATA)>
  8.         <!ATTLIST model year ID #REQUIRED>
  9.     <!ELEMENT km (#PCDATA)>
  10.         <!ATTLIST km usagetype (private | business) #REQUIRED>
  11.     <!ELEMENT descr (bodytype, colour)>
  12.         <!ATTLIST vehicle rego ID #REQUIRED>
  13. ]>
  14.  
  15. <inventory>
  16.    <vehicle rego="__">
  17.       <make></make>
  18.       <model year="__"></model>
  19.       <km usagetype="___"></km>
  20.       <descr>
  21.            <bodytype></bodytype>
  22.            <colour></colour>
  23.       </descr>
  24.       <photo></photo>
  25.     </vehicle>
  26. </inventory>
  27.  
I'm in the process of validating it but haven't quite finished doing so. Please let me know if what i've got so far is looking right. All suggestions and feedback is appreciated! =)
Mar 19 '08 #1
2 2068
Hi,

I can't catch u ur queries. Anyway i found some error in ur xml. I list here for ur reference.

Element bodytype, colour & photo not be declared.
Like this

<!ELEMENT bodytype #PCDATA)>
<!ELEMENT colour #PCDATA)>
<!ELEMENT photo #PCDATA)>


Year declare as id.So we must follow id rule for the year attribute of model. Suppose u want to create attribute like this then u want to change

<!ATTLIST model year CDATA #REQUIRED>

else

<model year="m1"></model>

Final File:

<?xml version="1.0"?>

<!DOCTYPE inventory [
<!ELEMENT inventory (vehicle?)>
<!ELEMENT vehicle (make, model, km, descr?, photo+)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ATTLIST model year ID #REQUIRED>
<!ELEMENT km (#PCDATA)>
<!ATTLIST km usagetype (private | business) #REQUIRED>
<!ELEMENT descr (bodytype, colour)>
<!ELEMENT bodytype ( #PCDATA)>
<!ELEMENT colour (#PCDATA)>
<!ELEMENT photo (#PCDATA)>
<!ATTLIST vehicle rego ID #REQUIRED>
]>

<inventory>
<vehicle rego="__">
<make></make>
<model year="cr2"></model>
<km usagetype="business"></km>
<descr>
<bodytype></bodytype>
<colour></colour>
</descr>
<photo></photo>
</vehicle>
</inventory>
---------------------------------------------------------------------------------------------------------------
Mar 19 '08 #2
anii
8
Hi there! Thanks a bunch for your quick reply.

Just wondering why you used PCDATA when declaring the elements
eg. <!ELEMENT make (#PCDATA)>
<!ELEMENT model (#PCDATA)>

instead of the others this website has:
#CDATA means the element contains character data that is not supposed to be parsed by a parser.
#PCDATA means that the element contains data that IS going to be parsed by a parser.
The keyword ANY declares an element with any content.

If a #PCDATA section contains elements, these elements must also be declared.
I mean like how did you know to choose PCDATA for all of them?

Also thank you for the code that you've put up. =) Its really helpful.
Mar 20 '08 #3

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

Similar topics

3
by: Imiro | last post by:
Hi, Trying to validate this dtd example with xml-spy 5 pro: This works: <!ELEMENT note (#PCDATA|body)*> <!ELEMENT body (#PCDATA)> This doesnt: <!ELEMENT note (#PCDATA|body)>
6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
8
by: Knighterrant | last post by:
I want to copy elements from one namespace to anothor, how to create the xslt? for example, the source data is: <s:mail xmlns:s="urn:source-namespace"> <s:subject>xxxx</s:subject>...
2
by: pawel.pabich | last post by:
Hajo, I know only one way of forcing element to have one or more childes: <xs:element name="saleOrSupplyMethod"> <BR/> <xs:complexType> <xs:choice> <xs:sequence> <xs:element...
0
by: ruediger | last post by:
Hi there, I want to set up an XML Schema for documents of the following structure: The <root> node contains - an optional <message> element with a text attribute, and - arbitrary further...
13
by: Jiho Han | last post by:
Here's the issue. You have a class, Class Person { public int id; public string firstname; public string lastname; }
8
by: VK | last post by:
Can be multiple instances of element used as the root element? That's a curly way of asking, but I did not come up with a better sentence, sorry. What I mean is with a document like: <?xml...
6
by: Lord0 | last post by:
Hi there, How do I define in a schema that an element (<element>) may have any content i.e. text, other elements, partial elements, angle brackets etc? So all of the following would be valid:...
1
by: DrDavey | last post by:
What are the advantages/disadvantages of using a choice of a several "sub-"elements with empty content (and no attributes) vs. simple content. Here's an example: Using simple content:...
0
by: joeller | last post by:
On October 13, 2006 Mark Rae wrote Hi, Firstly, I have not the slightest intention of using framesets - the reason for this post is merely to ask for assistance in furthering my understanding of...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.