Loading XML files

Prev Next

Introduction

With the procedure table load(), B4P loads complete XML files. The XML file will be put into a structured table. The table will contain following header names:

XML Level Nesting level. Begins with 1
XML Tag Applied tag. E.g. <Country>; puts "Country" into a new row at column "XML Tag".
XML Usage <Country> specifies "Start",
</Country> specifies "End", and
<Country/> specifies "Empty".
XML Contents Payload contents following the tag. E.g. <Country>UK<Country/> specifies "UK". Note: All ine breaks are included in the contents.
XML Attributes Lists all attribute names (but not the values) referenced in the XML tag
Additional columns:
Atribute names
The table gets additional columns with header names corresponding to the identified attribute names. Whenever attributes are specified in the tags, then the attribute values are listed below these headers.

       table load( t, "Examples\Example.xml", TEXT );

       echo("This is the XML file:");
       table list( t );

       table load( t, "Examples\Example.xml", XML );

       echo; echo;
       echo("This are the loaded contents from the XML file:");
       table list( t );
This is the XML file:
    0 : <?xml encoding=utf-8 ?>                                                                                              
    1 :                                                                                                                      
    2 : <Country type = nation  govt='monarchy' language = "english">GB<name> Great  Britain <deutsch/>Grossbritannien</name>
    3 :  <capital>London</capital>                                                                                           
    4 : </Country>                                                                                                           
    5 : <Country type=nation>DE<name>Germany<deutsch/>Deutschland</name>                                                     
    6 :  <capital>Berlin</capital>Nice city                                                                                  
    7 : </Country>                                                                                                           
    8 :                                                                                                                      



This are the loaded contents from the XML file:
    0 : XML Level | XML Tag | XML Usage | XML Contents     | XML Attributes     | type   | govt     | language
    1 : 1         | Country | Start     | GB               | type,govt,language | nation | monarchy | english
    2 : 2         | name    | Start     |  Great  Britain  |                    |        |          |         
    3 : 3         | deutsch | Empty     | Grossbritannien  |                    |        |          |         
    4 : 2         | name    | End       |                  |                    |        |          |         
      :           |         |           |                  |                    |        |          |         
    5 : 2         | capital | Start     | London           |                    |        |          |         
    6 : 2         | capital | End       |                  |                    |        |          |         
      :           |         |           |                  |                    |        |          |         
    7 : 1         | Country | End       |                  |                    |        |          |         
    8 : 1         | Country | Start     | DE               | type               | nation |          |         
    9 : 2         | name    | Start     | Germany          |                    |        |          |         
   10 : 3         | deutsch | Empty     | Deutschland      |                    |        |          |         
   11 : 2         | name    | End       |                  |                    |        |          |         
      :           |         |           |                  |                    |        |          |         
   12 : 2         | capital | Start     | Berlin           |                    |        |          |         
   13 : 2         | capital | End       | Nice city        |                    |        |          |         
      :           |         |           |                  |                    |        |          |         
   14 : 1         | Country | End       |                  |                    |        |          |         

Try it yourself: Open LIB_Features_Loading_XML_files.b4p in B4P_Examples.zip. Decompress before use.

See also

table load
Loading HTML files
Loading XML files
Loading JSON files