• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Element or Attribute

 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
10. Which of the following DOES NOT correctly describe a tradeoff between using attributes and elements to contain data?
A. Attribute values cannot contain general entity references
B. Element content may not contain unparsed entity references
C. Attributes cannot contain element specifications
D. Element content cannot contain element identifiers (an ID attribute) that are recognized by the XML parser as such
 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Is D the right answer for above question
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right becuase D is wrong.
D is wrong becuase the following is right

Cheers,
Dan
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
I think xsd:ID can be used only for declaring attributes in the schema. We cannot use it for defining the element content to the best of my knowledge. We can anyway enforce uniqueness for element content using the "key" stuff. Please correct me if i'm wrong.
Thanks.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
Based on my testing and reading xsd:ID can be used for attributes and for elements.
The specification http://www.w3.org/TR/xmlschema-2/#ID says -
For compatibility (see Terminology (�1.4)) ID should be used only on attributes.

Which implies, as I understand it, that it’s available elsewhere.
Cheers,
Dan
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that question asking specifically about schemas, or about DTDs?
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
I checked my schema on an on-line schema validator and it had no problem using xsd:ID for the element type.
I think Ron has a very valid point here. If we look at the question, nothing was mentioned as to whether Schemas or DTDs are using for the validation purpose. If so, D will be true if DTDs are used.
I'm inclining toward the option "A" being wrong.
Please look at the following simple xml file with a general entity reference being use for the attribute. I could run it thru the DOM parser and it could successfully resolve the value for the reference(&localEntity).
================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE root SYSTEM "sample.dtd"[
<!ELEMENT root ANY>
<!ELEMENT aa1 (#PCDATA)>
<!ATTLIST root attr1 CDATA #REQUIRED>
<!ENTITY localEntity "pcdat">
<!ENTITY % parEntt1 "<!ELEMENT car ANY>">
<!ELEMENT jayadev:ele EMPTY>
<!ATTLIST jayadev:ele dev CDATA "pulaparty">
<!ELEMENT jayadev EMPTY>
<!ATTLIST jayadev dev CDATA "pulaparty">
]>

<root attr1="&localEntity;">
&localEntity;
<jaya/>
<car><root attr1="12"/></car>
<jayadev dev="jpulapar"><?PIData xxxx=yyyy ?></jayadev>
</root>
================================================
Please correct me for any mistakes here as i'm not very sure about these DTDs and entities stuff. I have to go thru them thoroughly.
Thanks for your inputs.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev,
A is without a doubt wrong. So A would be a better answer than D.
Cheers,
Dan
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic