Is there is an interface to deal with as XML file?

117 Views Asked by At

I made an application that depends on the data taken form an XML file, and if the user want to update something in that application he have to change the data contained in that xml file, but for sure i can't ask the user to open the XML file and change it himself, so is there is a way or an interface that can be used to edit this XML file or something that helps me build that interface?

HINT: the changes that have to be made to the xml file to update the application is a slight changes like adding or removing a node.

1

There are 1 best solutions below

3
Rahul Tanwani On

Yes, its possible to read and write XML files using XML parsers. Every programming language has bunch of libraries to deal with the same. For python, we can use xml or lxml

with open("xmlfile.xml", "rw") as f:
    doc = ET.parse(f)
    print "Original XML Contents :"
    print ET.tostring(doc)
    root = doc.getroot()
    library = root.find("library")
    library.text = "lxml"
    print "Updated XML Contents :"
    updated = ET.tostring(doc)
    print updated

This produces, output like:

Original XML Contents :
<root>
    <library>xml</library>
    <language>python</language>
</root>
Updated XML Contents :
<root>
    <library>lxml</library>
    <language>python</language>
</root>

This updated XML can easily be written to a file. For more info checkout: lxml

Thanks!