Xml: Difference between revisions

From wikinotes
(Created page with "{{ TODO | Generalized documentation here }} See python etree .")
 
No edit summary
Line 4: Line 4:


See [[python etree]] .
See [[python etree]] .
= Components =
<blockquote>
{{ expand
| Node/Element
|
<source lang="xml">
<tag>                      <!-- node/element -->
    <subtag>...</subtag>
    <subtag>...</subtag>
</tag>
<tag/>                    <!-- empty element -->
</source>
* An Element is marked by a start/end Tag (<code><tag>...</tag></code>)
* A collection Elements is a Node
* An empty element can be marked without an open/closing tag by placing the '/' at the end of the tag (<code><tag/></code>)
Syntactically, nodes/elements are indistinguishable - but generally a node is used to refer
to a top-level grouping of elements (at the level where it means something).
}}
{{ expand
| Tag
|
<source lang="xml">
<project attrib_A="A" attrib_B="B"></project>    <!-- attributes -->
<project myproject></project>                    <!-- text -->
<project/>                                      <!-- empty element -->
</source>
* Tags may contain attributes (<code><nowiki><tag a="a" b="b">...</tag></nowiki></code>)
* Tags may also be assigned a text value (<code><tag "text">...</tag></code>)
}}
{{ expand
| Namespace
|
<source lang="xml">
<tag
  xmlns="http://www.w3.org/foo/"          <!-- define default namespace -->
  xmlns:x="http://www.w3.org/TR/html4/"  <!-- define x: namespace -->
  xmlns:y="http://www.w3.org/blah/"      <!-- define y: namespace -->
>
    <x:person></x:person>  <!-- becomes  <http://www.w3.org/TR/html4/person> -->
    <y:person></y:person>  <!-- becomes  <http://www.w3.org/blah/person> -->
    <cat></cat>            <!-- becomes  <http://www.w3.org/foo/cat> -->
</tag>
</source>
<code>xmlns</code> (xml-namespace) can be declared in the root element. The
when parsed, the XML element replaces the prefix with the defined URI. This is
used to prevent name-clashes.
There are two types of notations for keys with namespaces.
* <code>{namespace}tag</code>
* <code>namespace#tag</code>
Apparently, it is possible to retrieve information about the namespace from these URLS.
I have not looked into this yet.
See this excellent tutorial <nowiki>https://www.w3schools.com/XML/schema_schema.asp</nowiki>
}}
{{ expand
| Schema
|
It is possible to make your XML object conform to a schema listed online.
I haven't fully looked into this yet.
See <nowiki>https://www.w3schools.com/XML/schema_schema.asp</nowiki>
}}
</blockquote><!-- Components -->

Revision as of 20:31, 22 August 2021

TODO:

Generalized documentation here

See python etree .

Components

Node/Element


<tag>                      <!-- node/element -->
    <subtag>...</subtag>
    <subtag>...</subtag>
</tag>

<tag/>                     <!-- empty element -->
  • An Element is marked by a start/end Tag (<tag>...</tag>)
  • A collection Elements is a Node
  • An empty element can be marked without an open/closing tag by placing the '/' at the end of the tag (<tag/>)

Syntactically, nodes/elements are indistinguishable - but generally a node is used to refer to a top-level grouping of elements (at the level where it means something).


Tag


<project attrib_A="A" attrib_B="B"></project>    <!-- attributes -->
<project myproject></project>                    <!-- text -->
<project/>                                       <!-- empty element -->
  • Tags may contain attributes (<tag a="a" b="b">...</tag>)
  • Tags may also be assigned a text value (<tag "text">...</tag>)

Namespace


<tag
  xmlns="http://www.w3.org/foo/"          <!-- define default namespace -->
  xmlns:x="http://www.w3.org/TR/html4/"   <!-- define x: namespace -->
  xmlns:y="http://www.w3.org/blah/"       <!-- define y: namespace -->
>
    <x:person></x:person>   <!-- becomes  <http://www.w3.org/TR/html4/person> -->
    <y:person></y:person>   <!-- becomes  <http://www.w3.org/blah/person> -->
    <cat></cat>             <!-- becomes  <http://www.w3.org/foo/cat> -->
</tag>

xmlns (xml-namespace) can be declared in the root element. The when parsed, the XML element replaces the prefix with the defined URI. This is used to prevent name-clashes.

There are two types of notations for keys with namespaces.

  • {namespace}tag
  • namespace#tag

Apparently, it is possible to retrieve information about the namespace from these URLS. I have not looked into this yet.


See this excellent tutorial https://www.w3schools.com/XML/schema_schema.asp

Schema

It is possible to make your XML object conform to a schema listed online. I haven't fully looked into this yet.

See https://www.w3schools.com/XML/schema_schema.asp