Python Forum
where indentation matters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where indentation matters
#1
i was looking around at the files for my desktop settings. these are in XML format. i thought XML was free form where indentation did not matter. what i see is a property naming structure where they indent property tags to create a hierarchical name structure. there appears to be no other means of creating a structure. is XML really like that, where indentation has a meaning, even if not the same meaning as the Python language?

  <property name="Net" type="empty">
    <property name="ThemeName" type="empty"/>
    <property name="IconThemeName" type="empty"/>
    <property name="DoubleClickTime" type="empty"/>
    <property name="DoubleClickDistance" type="empty"/>
    <property name="DndDragThreshold" type="empty"/>
    <property name="CursorBlink" type="empty"/>
    <property name="CursorBlinkTime" type="empty"/>
    <property name="SoundThemeName" type="empty"/>
    <property name="EnableEventSounds" type="empty"/>
    <property name="EnableInputFeedbackSounds" type="empty"/>
    <property name="FallbackIconTheme" type="empty"/>
  </property>
  <property name="Xft" type="empty">
    <property name="DPI" type="empty"/>
    <property name="Antialias" type="empty"/>
    <property name="Hinting" type="empty"/>
    <property name="HintStyle" type="empty"/>
    <property name="RGBA" type="empty"/>
    <property name="Lcdfilter" type="empty"/>
  </property>
if there was some other indication of nesting and/or levels, i would not suspect indentation. i am wondering what can read this and get the true meaning.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
(Feb-09-2022, 01:16 AM)Skaperen Wrote: is XML really like that, where indentation has a meaning, even if not the same meaning as the Python language?
Indentation in XML has no meaning as in Python where is required.
So a XML document would parse fine even if have no Indentation.

Should of course use indentation as it makes it far easier for human readers to work with and take in the structure at a glance.
If someone post XML that has no indentation it have happed sometime on forum,
i take into CodePen(or VS Code) that has auto formatter for HTML/XML/CSS.
Before:
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
After CodePen formatter:
<bookstore>
  <book category="children">
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="web">
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>
stevendaprano and BashBedlam like this post
Reply
#3
your bookstore example has an implied indentation based on human understanding of the tag names. but, if all the tag names are the same (e.g. "property") then how do you get the structure? i have created my own data structure to use in genealogy that uses indentation to have subordinate data such as a person's spouse and then their children.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(Feb-10-2022, 06:15 AM)Skaperen Wrote: but, if all the tag names are the same (e.g. "property") then how do you get the structure?
Formatter and and also humans will/should follow the XML rules.
So all XML syntax most have closing tag unlike HTML where can get away without.
So on same names would look at closing tag,then indentation base on what is the first tag.
Can test your example without indentation.
<property name="Net" type="empty">
<property name="ThemeName" type="empty"/>
<property name="IconThemeName" type="empty"/>
<property name="DoubleClickTime" type="empty"/>
<property name="DoubleClickDistance" type="empty"/>
<property name="DndDragThreshold" type="empty"/>
<property name="CursorBlink" type="empty"/>
<property name="CursorBlinkTime" type="empty"/>
<property name="SoundThemeName" type="empty"/>
<property name="EnableEventSounds" type="empty"/>
<property name="EnableInputFeedbackSounds" type="empty"/>
<property name="FallbackIconTheme" type="empty"/>
</property>
<property name="Xft" type="empty">
<property name="DPI" type="empty"/>
<property name="Antialias" type="empty"/>
<property name="Hinting" type="empty"/>
<property name="HintStyle" type="empty"/>
<property name="RGBA" type="empty"/>
<property name="Lcdfilter" type="empty"/>
</property>
In CodePen after format.
<property name="Net" type="empty">
  <property name="ThemeName" type="empty" />
  <property name="IconThemeName" type="empty" />
  <property name="DoubleClickTime" type="empty" />
  <property name="DoubleClickDistance" type="empty" />
  <property name="DndDragThreshold" type="empty" />
  <property name="CursorBlink" type="empty" />
  <property name="CursorBlinkTime" type="empty" />
  <property name="SoundThemeName" type="empty" />
  <property name="EnableEventSounds" type="empty" />
  <property name="EnableInputFeedbackSounds" type="empty" />
  <property name="FallbackIconTheme" type="empty" />
</property>
<property name="Xft" type="empty">
  <property name="DPI" type="empty" />
  <property name="Antialias" type="empty" />
  <property name="Hinting" type="empty" />
  <property name="HintStyle" type="empty" />
  <property name="RGBA" type="empty" />
  <property name="Lcdfilter" type="empty" />
</property>
Reply
#5
so the structure is formed based on what is open or not around any point in the XML sequence and the indentation is for reading convenience by biological units.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
A quick search reveals that in XML there is significant white space and insignificant white space. Learn the exact rules!
Reply
#7
yeah, i need to study it beyond the promotional info about it. i've had trouble with it, before. i'm not so sure, anymore, that it is so great for storing data.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020