0

What are my options if I want to create a sample XML file in python?

The xml I want looks like is below also i want to take some input from user through cmdline arguments for example Nodename input came from user in ID only Machine field came from user input .

<?xml version="1.0" ?>
<Windows 
MachineClass="Windows"
xmlns="https://graphit.co/schemas/v2/MARSSchema"
ID="abc.com:brd-del:Machine:LDN1HAS1"
NodeName="LDN1HAS1"
NodeType="Machine"
CustomerID="abc.com"
CustomerName="abc.com"
OSName="Windows2016"
OSMajorVersion="10"
OSMinorVersion="0">
<SourceCiId><Content Value="LDN1HAS1"/></SourceCiId>
<FQDN><Content Value="LDN1HAS1.abc.com"/></FQDN>
<IPAddress><Content Value="10.101.248.128"/></IPAddress>
<Location><Content Value="London"/></Location>
<EnvironmentClassifier><Content Value="Production"/></EnvironmentClassifier>
</Windows>
1

1 Answer 1

1
import xml.etree.cElementTree as ET

root = ET.Element("root")
doc = ET.SubElement(root, "doc")

ET.SubElement(doc, "field1", name="blah").text = "some value1"
ET.SubElement(doc, "field2", name="asdfasd").text = "some vlaue2"

tree = ET.ElementTree(root)
tree.write("filename.xml")

for example.

see: Creating a simple XML file using python for more

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.