Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 8th, 2004, 04:03 PM
Random Random is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 72 Random User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 47 m 23 sec
Reputation Power: 10
Advice for a script

Hello,

Looking for advice as to what would be the best way of making this script. What I have are 10 constant smal xml files
which would need to be combined together in different combinations. The files are named and not numbered so depending on which ones I need right now they would just get combined and copied together to a separate file.

Thanks
Random

Reply With Quote
  #2  
Old June 8th, 2004, 05:40 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Is there any sort of criterion by which you are combining them? Or do you not know that until it's time to combine them? The easiest way of concatenating files together depends upon your environment. In a Linux environment, you simply use cat. cat foo bar > fooandbar. Not sure what the best way is to do it in a Windows or Mac environment.

Of course, if you are doing more than just verbatim concatenation (like you want to combine them but not concatenate), then that gets trickier...
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #3  
Old June 9th, 2004, 11:01 PM
Random Random is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 72 Random User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 47 m 23 sec
Reputation Power: 10
No there is no criterion by which you are combining them. It's all on the fly type of requests where I am told which are needed and then open a new txt file in Windows and just copy them over one after another.

Random

Reply With Quote
  #4  
Old June 10th, 2004, 03:27 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
You cannot just concatenate XML files and expect the result to be valid XML. A valid XML file has one and only one root node, and everything else must be within that root. If you concatenate two or more XML files then you will have more than one root. You also only want the file metadata appearing at the head of the file, not repeated in the middle.

You could have your files containing snippets of XML, and insert them into the root element, something like this:

Code:
#untested code - caveat emptor

xmlRoot = '''
<?xml version="1.0"?>
<root>
%s
</root>
'''

files = [ 'file1.xml', 'file2.xml', 'file3.xml' ]

xmlTexts = [ open(file, 'r').read() for file in files ]
xml = xmlRoot % ''.join(xmlTexts)
print xml


This will produce syntactically correct XML, but it may or may not be semantically correct since the ordering of nodes may be significant.

Dave - The Developers' Coach

Reply With Quote
  #5  
Old June 10th, 2004, 11:02 PM
Random Random is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 72 Random User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 47 m 23 sec
Reputation Power: 10
Thanks Dave.

I will utilize your advice and see what I can do.

Random

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Advice for a script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap