Sign In/My Account | View Cart  
advertisement

Article:
 Converting Between XML and JSON
Subject: #text should always work
Date: 2006-05-31 15:49:30
From: bkc

I suggest that even for the simple element text case, e["#text"] should also always work.


This way, references to the element's text will work whether there are attributes or not on that element.


Programmers who are certain their xml data will *always* have a known format can choose to use the less verbose e.text reference.


Also, an element named 'text' should take precedence over the text content of a mixed-mode element. That is, e["#text"] would reference the text part, and e.text would reference the child element named 'text'.




No Previous Message Previous Message   Next Message Next Message


Titles Only Titles Only Newest First
  • #text should always work
    2006-06-14 04:18:08 stefan@goessner.net

    This is a good point. Unfortunately we cannot have both 'e' *and* 'e["#text"]' resulting in the same textual content.


    I agree, that having always to use 'e["#text"]' for accessing an element's text generally is more consistent.


    Frequently programmers know their xml/json structure and want to use the less verbose 'e' form, which is what you also mentioned.


    A possible solution might be to let the user control behaviour by an additional configuration parameter.


    Please note however, that there is only an 'e.text' when element 'e' has a child element 'text'.


Sponsored By: