Liversalts

lab01.py

Mar 3rd, 2021
727
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Import modules
  2. import sys
  3. from helper import *
  4.  
  5. import xml.etree.ElementTree as ET
  6.  
  7. import xml.dom.minidom as MD
  8.  
  9. # Main function
  10. if __name__ == "__main__":
  11.     #########################################
  12.     #              Procedure 1              #
  13.     #########################################
  14.     # Add print statement here
  15.  
  16.  
  17.     #########################################
  18.     #              Procedure 2              #
  19.     #########################################
  20.     print('##################')
  21.     print('###### YAML ######')
  22.     print('##################')
  23.  
  24.     # Open the user.yaml file as read only
  25.  
  26.         # Load the stream using safe_load
  27.  
  28.     # Print the object type
  29.     print("Type of user_yaml variable:")
  30.  
  31.     print('----------------------')
  32.  
  33.     # Iterate over the keys of the user_yaml and print them
  34.     print('Keys in user_yaml:')
  35.  
  36.     print('----------------------')
  37.  
  38.     # Create a new instance of class User
  39.  
  40.     # Assign values from the user_yaml to the object user
  41.  
  42.     # Print the user object
  43.     print('User object:')
  44.  
  45.  
  46.     #########################################
  47.     #              Procedure 3              #
  48.     #########################################
  49.     print('##################')
  50.     print('###### JSON ######')
  51.     print('##################')
  52.  
  53.     # Create JSON structure from the user object
  54.    
  55.     # Print the created JSON structure
  56.     print('Print user_json:')
  57.  
  58.     print('----------------------')
  59.  
  60.     # Create JSON structure with indents and sorted keys
  61.     print('JSON with indents and sorted keys')
  62.  
  63.  
  64.     #########################################
  65.     #              Procedure 4              #
  66.     #########################################
  67.     print('######################')
  68.     print('# XML - Element Tree #')
  69.     print('######################')
  70.  
  71.     # Parse the user.xml file
  72.  
  73.     # Get the root element
  74.  
  75.     # Print the tags
  76.     print('Tags in the XML:')    
  77.  
  78.     print('----------------------')
  79.  
  80.     # Print the value of id tag
  81.     print('id tag value:')
  82.  
  83.     print('----------------------')
  84.  
  85.     # Find all elements with the tag address in root
  86.  
  87.     # Print the adresses in the xml
  88.     print('Addresses:')
  89.  
  90.     print('----------------------')
  91.    
  92.     # Print the elements in root with their tags and values
  93.     print('Print the structure')    
  94.  
  95.     # Parsing XML files with MiniDOM
  96.     print('######################')
  97.     print('### XML - MiniDOM ####')
  98.     print('######################')
  99.  
  100.     # Parse the user.xml file
  101.  
  102.     # Print the tags
  103.  
  104.     print('----------------------')    
  105.  
  106.     # Accessing element value
  107.     print('Accessing element value')
  108.  
  109.     print('----------------------')
  110.  
  111.     # Print elements from the DOM with tag name 'address'
  112.     print('Addresses:')
  113.  
  114.     print('----------------------')
  115.  
  116.     # Print the entire structure with printNodes
  117.     print('The structure:')
  118.  
  119.  
  120.     #########################################
  121.     #              Procedure 5              #
  122.     #########################################
  123.     print('######################')
  124.     print('#   Use Namespaces   #')
  125.     print('######################')
  126.  
  127.     # Parse the user.xml file
  128.  
  129.     # Get the root element
  130.  
  131.     # Define namespaces
  132.  
  133.     # Set table as the root element
  134.  
  135.     # Elements in NS a
  136.     print('Elements in NS a:')  
  137.  
  138.     print('----------------------')
  139.  
  140.     # Elements in NS b
  141.     print('Elements in NS b:')
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×