How to save modified xml file to hard disk

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PythonUser1
    New Member
    • Jun 2008
    • 4

    How to save modified xml file to hard disk

    Hi,

    I have modified a xml file using 4suite and usable to save it to disk.

    Please give a sample code to do so.

    Thanks,
    PyhtonUser
  • raubana
    New Member
    • Feb 2008
    • 55

    #2
    You might have to give us some more info as to what your trying to do.
    This could be difficult if we don't know how to help.

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      If you want to 'save' a file, open the file in write ('w' or 'wb', depending) mode and write the data you want to the file. If the file already exists and you're just changing a few things, I don't know a way to do it without loading in the file, changing what needs to be changed, and writing it back.

      Comment

      • jlm699
        Contributor
        • Jul 2007
        • 314

        #4
        Originally posted by Laharl
        open the file in write ('w' or 'wb', depending) mode and write the data you want to the file
        [code=python]
        fh = open( 'myfile.xml', 'w' ) # You can swap 'w' for 'wb' for a binary write
        fh.write( data )
        fh.close()
        [/code]

        Comment

        • mallikabiswas
          New Member
          • Jun 2008
          • 2

          #5
          Hi all,
          I am using python 2.5.
          Using 4 suite I am able to remove the node,but not able to save back the changes in the xml file.
          my code:
          import sys
          import os
          from Ft.Xml import XUpdate
          from Ft.Xml import Domlette, InputSource
          from Ft.Lib import Uri

          reader = Domlette.Nonval idatingReader
          xureader = XUpdate.Reader( )

          source = reader.parseUri ("file:D:\\lear ning python\\pyrhon and xml\\test\\docu ment.xml")




          isrc = InputSource.Def aultFactory.fro mUri("file:D:\\ learning python\\pyrhon and xml\\test\\remo venode.txt")
          xupdate = xureader.fromSr c(isrc)

          processor = XUpdate.Process or()
          processor.execu te(source, xupdate)

          Domlette.Print( source)


          removenode.txt file:

          <xup:modificati ons version="1.0"
          xmlns:xup="http ://www.xmldb.org/xupdate"
          xmlns:w="http://schemas.openxml formats.org/wordprocessingm l/2006/main">
          <xup:remove select="w:docum ent/w:body/w:sectPr/w:pgSz"/>
          </xup:modificatio ns>


          Please help.
          Thanks.

          Mallika

          Comment

          Working...