Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > It seems that XPath does not distinguish between an inexistent pathand a null string?

Reply
Thread Tools

It seems that XPath does not distinguish between an inexistent pathand a null string?

 
 
Joe Kesselman
Guest
Posts: n/a
 
      06-14-2012
> I.e., there is no preference at all (<someword></someword> vs.
> <someword/>) if the XML document is intended to be processed by an XML
> processor.


Speaking as someone who has been working with XML for over a decade now,
and who was involved in the design of the DOM: Exactly. XML considers
this *ONLY* a syntactic difference, with no semantic meaning.
<someword/> is just shorthand for <someword></someword>.

If you need to distinguish between empty and null, see the other thread:
Either use an attribute to distinguish the two cases, or leave the
element out entirely.


--
Joe Kesselman,
http://www.love-song-productions.com...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      06-27-2012
On 14/06/12 11:04, Alain Ketterlin wrote:
> "japisoft" <> writes:
>
>> When your document is parsed, the final result has no difference. But
>> from the schema/DTD view, there's a
>> difference because
>>
>> <!ELEMENT somework EMPTY>
>>
>> and
>>
>> <!ELEMENT somework (#PCDATA)>
>>
>> are not equal, so write :
>>
>> <someword></someword>
>>
>> is equal to
>>
>> <someword/>
>>
>> is only true if the content type is (#PCDATA) or

>
> Do you have a source for this claim?


It's been a long time, but I think you'll find the discussion in the
archives of the XML SIG at the time. I seem to remember we did it to
death and the consensus was that XML should not distinguish between the
two forms.

> I think it's wrong. (Not the fact
> that #PCDATA and EMPTY are different, the fact that there is a
> difference between the two forms of empty elements.)


Officially there is no difference. In practice, if your parser has
access to a DTD or Schema, it would be possible for it to detect if
content was allowed or not.

> The XML recommandation says: "If an element is empty, it must be
> represented either by a start-tag immediately followed by an end-tag or
> by an empty-element tag." (Section 3.1)
>
> The only difference I know of is mentioned in the next paragraph: "For
> interoperability, the empty-element tag must be used, and can only be
> used, for elements which are declared EMPTY." And "For interoperability"
> is defined earlier as non-binding.


It is still regarded as good practice in the publishing field, where the
semantics of potential mixed content can be important. It also serves as
a reminder to those who examine the markup that the element type cannot
have any content, rather than the current element just being empty by
chance.

///Peter
 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      06-28-2012
On 6/27/2012 3:54 PM, Peter Flynn wrote:
> Officially there is no difference


Correct. If you doubt this, look at the W3C's XML Infoset document (the
official statement of what information an XML document represents),
which has absolutely no way to represent this distinction. Whether
<foo></foo> or <foo/>, the infoset represents it as an element with no
child nodes.

There are stylistic conventions which may cause one or the other to be
preferred by specific applications -- "for interoperability" with SGML
tools being one of those, though realistically there is now enough XML
tooling out there that very few people are still trying to put XML
through SGML tools. But that's strictly style, not substance.

If you want to distinguish empty vs. null, XML lets you do so by adding
an attribute, or a child element, that your application recognizes as
signifying that the content is null. XML Schema suggests an attribute
for that purpose. Adopt it.

--
Joe Kesselman,
http://www.love-song-productions.com...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."


 
Reply With Quote
 
Manuel Collado
Guest
Posts: n/a
 
      06-28-2012
El 28/06/2012 6:23, Joe Kesselman escribió:
> On 6/27/2012 3:54 PM, Peter Flynn wrote:
>> Officially there is no difference

>
> Correct. If you doubt this, look at the W3C's XML Infoset document (the
> official statement of what information an XML document represents),
> which has absolutely no way to represent this distinction. Whether
> <foo></foo> or <foo/>, the infoset represents it as an element with no
> child nodes.
>
> There are stylistic conventions which may cause one or the other to be
> preferred by specific applications -- "for interoperability" with SGML
> tools being one of those, though realistically there is now enough XML
> tooling out there that very few people are still trying to put XML
> through SGML tools. But that's strictly style, not substance.


Just a minor hint: IIRC, if interoperability with SGML tools matters,
the preferred notation for an empty element is <foo />. Note the space
before the slash.

>
> If you want to distinguish empty vs. null, XML lets you do so by adding
> an attribute, or a child element, that your application recognizes as
> signifying that the content is null. XML Schema suggests an attribute
> for that purpose. Adopt it.
>

--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Inexistent instance variable value Ricardo Amorim Ruby 1 08-06-2009 02:08 PM
Distinguish between empty string and no children, in XPath 2? Arndt Jonasson XML 6 09-07-2008 04:48 AM
Distinguish between empty string and no children, in XPath 2? Arndt Jonasson XML 0 09-05-2008 11:30 AM
Does C distinguish between a C source file and a text file? amit C Programming 4 08-11-2006 07:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57