On 21/01/2019 03:17, mhysnm1...@gmail.com wrote:

> confused with some XML terminology.
> 
> What is:
> Tag – I think it is the <key> in the itunes library file.
> 
> Text = The text between the <key>
> 
> Attrib  -- don’t know.
You really need to find a tutorial on XML
(And maybe even start with one on HTML?) To parse out
the information from an XML file, even using a parser
like etree, requires that you understand the structure
of the file. And that includes really understanding
the terminology.

In very simple terms an XML file (or more
correctly a "document") is a tree structure.
It starts with a parent node then that has
child nodes. Each child may have children
of its own ad infinitum. Each node is
identified by a pair of tags which are simply
names between angle brackets - <key> for example
There is a start and closing tag, the closing
one having a '/' at the start. Between the tags
is the text (which may include more tags for
child nodes).

tags can also include attributes which are names
inside the opening tags brackets, often with an
assigned value.

The rules governing what constitutes a valid tag
or attribute and which tags can be nested within
which others are all defined in a definition file,
often called a schema or DTD  file. There is a
standard header that tells the reader where to
find the schema.

You might also see comments which are just notes
to explain whats going on and contain no actual
data...

Here is a meaningless pseudocode example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE containing the DTD FILE location>
<document>
   <!-- A comment goes here -->
   <child1>
      Some text here
   </child1>
   <child2>
      Child2 text here
      <subchildA>Text here on same line</subchildA>
      More child2 text
      <subchildB>
           Text for subchild
      </subchildB>
      Finishing off child2 text...
   </child2>
   <child3  attribute1  attribute2="SomeValue">
      More text here, could be lorts of it over many lines
   </child3>
   <childwithopenandclosecombined   attribute3="42" />
   <!-- the tag above is self closing because of the / at the end -->
</document>

For more than that google XML tutorial...

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to