imporve readability NIST_data_leakage_01_registry.ppt

This commit is contained in:
Frank Xu
2023-09-15 21:49:41 -04:00
parent 8236a46502
commit 53836b0db4
4 changed files with 24 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import xml.etree.ElementTree as ET
tree = ET.parse("bookstore_removed_ns.xml")
tree = ET.parse("bookstore.xml")
root = tree.getroot()
# Iterate through the book elements and print their category attributes

View File

@@ -13,5 +13,5 @@ for price_element in root.findall(".//price"):
updated_xml_content = ET.tostring(root, encoding="utf-8")
# Save the updated XML to a new file
with open("bookstore_updated.xml", "wb") as f:
with open("bookstore_updated_price.xml", "wb") as f:
f.write(updated_xml_content)

View File

@@ -0,0 +1,20 @@
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>31.0</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>30.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>40.95</price>
</book>
</bookstore>

View File

@@ -1,7 +1,6 @@
import xml.etree.ElementTree as ET
import xml.dom.minidom as minidom
tree = ET.parse("SecurityEvt_ns_removed.xml")
tree = ET.parse("securityEvt_formatted.xml")
root = tree.getroot()
# Find the first Event element
@@ -12,13 +11,7 @@ if first_event is not None:
# Convert the first Event element to a string with pretty formatting
first_event_str = ET.tostring(first_event, encoding="unicode", method="xml")
# Parse the XML content
dom = minidom.parseString(first_event_str)
# Pretty print the XML content
pretty_xml = dom.toprettyxml(indent=" ")
# Print the nicely formatted XML
print(pretty_xml)
print(first_event_str)
else:
print("No Event elements found in the XML.")