OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] RE: Take 2 - How do you replace comments from XML?

[ Lists Home | Date Index | Thread Index ]

Dominica DeGrandis wrote:
> Ok -  I left out some important information in my request for help below.
> The file I'm working with is a MS .NETFramework system file under
> C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG called machine.config.
> It's an XML file.   It uses comments to separate sections of configurations.
> I'm trying to replace custom configurations under the <appSettings> node
> that begins and ends with comments.

Ahh... misread your post, sorry. Then you probably want a line 
oriented thing to plonk in a magic marker tag

def insertMarkers(before, after):
     ifile = open("machine.config")
     ofile = open("machine-tmp.config", "w")

     for line in ifile:
             if line.find(before) != -1:


             if line.find(after) != -1:

if __name__ == "__main__":
   insertMarkers("Start xxxx.Net", "End xxxx.Net")

Now you can select the magic.marker blocks in machine-tmp.config, do 
whatever you like with that document, and write back to the original 
minus the tags. It sucks for sure, but without knowing exactly what 
you're trying to do, are you certain that there isn't enough 
information in the XML (minus comments) to pick out what you need?

Bill de hÓra


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS