Hi, I have a few problems regarding XML's syntax. Are attribute names allowed to have space in between(ie. more than one word, like first color="red")? If so, how can a parser tell where the element name ends and where attribute name begins?
Hi Cameron, According to Teach YourSelf XML p192 attribute names can include spaces; element names cannot. Think the parser takes anything between the start of a tag '<' and the first space to be an element name; anything between the first space and the '=' as an attribute name. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
Attribute, and their values, are attached to element, so it has to follow the naming rule with element. Such as beginning with a letter or a underscore, you will receive errors on $Priority, 2Choice.... as attribute name. Moreover, you can allow to have only ONE attribute name with a given name of element. It doesn't behave like element to be able to have multi-occurence. Ex: <Items> <Item> ......</Item> <Item> ......</Item> <Items> enoc
Leverager of our synergies
posted 18 years ago
There were a lot of questions and doubts regarding value of certification (SCJP primarily), but what is unquestionable, that Certified bring discussion to the higher level. Thanks, Enoc! Jane, you should write to Teach YourSelf XML people and tell them about their mistake! They have to mention you in their next edition! Yes, I tried to code an attribute with a space in it�s name and checked it with XML Spy (I believe it uses MSXML) and with Xalan (which I believe uses Xerces parser).
More detailed. In XML name: first symbol= a letter OR _ OR : ( �:� symbol is not recommended because of possible conflict with namespaces). Of course, letter can be from any language supported by Unicode. So practically we can start our name either with letter or _ myName or _myName any other symbols: letter OR . OR - OR _ OR : OR <digit> OR <CombiningChar> OR <Extender> where <digit> can be any digit from 0-9 diapason + digits from other languages: Arabic-Indic Digits set, Bengali Digits, Tamil Digits, Tibetian Digits... <CombiningChar> - special character such as accents and tilde, can be used in other languages. <Extender> = even more exotic symbols, such as �vertical Kana Repeat Mark�, for example If to simplify picture and restrict us with English characters, all we can have is my_Name my.Name1 _my-Name2 no spaces, no punctuations besides . - _
In cases like this where there is some doubt, don't refer to somebody's book - refer to the specification. The XML 1.0 specification section 3.3 has this: Attribute-list Declaration  AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'  AttDef ::= S Name S AttType S DefaultDecl
" ... The Name in the AttlistDecl rule is the type of an element. At user option, an XML processor may issue a warning if attributes are declared for an element type not itself declared, but this is not an error. The Name in the AttDef rule is the name of the attribute." Since "Name" is used in both productions, both elements and attributes must be constructed according to the same rules. The rules are given in section 2.3: Names and Tokens  NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender  Name ::= (Letter | '_' | ':') (NameChar)*
So whitespace is not allowed in either element names or attribute names.
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Liar, liar, pants on fire! refreshing plug:
how do I do my own kindle-like thing - without amazon