473,513 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to make the deepest child in xml from data.txt

12 New Member
how to make the deepest child in xml from data.txt

lindu
bali
23
indonesia
male
surfing
gardening

from that file i want make data.xml like this
<people>
<profile>
<name>lindu</name>
<home>bali</home>
<age>23</age>
<country>indonesia</country>
<hobby>
<most>surfing</most>
<little>gardening</little>
</hobby>
</profile>
</people>

without change the code every file i free to make a new data.xml
i mean i can make data.xml from data.txt without watch the content and i free to define the low for child in xml
Nov 6 '08 #1
1 1133
nishi2rock
3 New Member
if all you want is to make another xml ( still a text file ) dont bother that it is xml and u can use just file operations to make the xml file.

Expand|Select|Wrap|Line Numbers
  1. TxtFileData = [aLine.strip() for aLine in open('data.txt').readlines()]
  2.  
  3. while "" in TxtFileData: TxtFileData.remove("")
  4. ## To remove any line in between if there is no data
  5.  
  6. XmlData = """
  7. <people>
  8. <profile>
  9. <name>%s</name>
  10. <home>%s</home>
  11. <age>%s</age>
  12. <country>%s</country>
  13. <gender>%s</gender>
  14. <hobby>
  15. <most>%s</most>
  16. <little>%s</little>
  17. </hobby>
  18. </profile>
  19. </people>
  20. """%(TxtFileData[0],TxtFileData[1],TxtFileData[2],TxtFileData[3],TxtFileData[4],TxtFileData[5],TxtFileData[6])
  21.  
  22. XmlFile = open('data.xml','w')
  23. XmlFile.write(XmlData)
  24. XmlFile.close()
  25.  
  26.  
it can be done in a much better way using xml.dom but this code will do if all you want is to convert the data to xml.

Please note that i have added gender node
Elaborate on "i free to define the low for child in xml"
Nov 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
1625
by: mike | last post by:
I have a parent window where I open a child window. In that child window I have some js that creates a row in the parent window, it looks like: if ( self.opener.document.update ) { var...
5
3277
by: Jeroen Ceuppens | last post by:
I need to put a new node at the end of the tree, that end is not te lowest in de list but the deepest (the one with the most + before it) Node A Node 1 Node 2 Node 3 Node 4: Deepest Node B:...
1
3577
by: Johann Blake | last post by:
I have a dataset that contains a parent table and a child table. A DataRelation exists between the two. I was under the impression from reading the VS docs that when I filled the parent table, the...
1
11537
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
3
6775
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
0
1138
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
4
2310
by: Rich | last post by:
Hello, I have a child form in an Mdi Parent form. I have 5 menu buttons on the Parent that I use to show the child form. Originally, in the Parent form on load event I had this line of code ...
1
1583
by: sparks | last post by:
I have a main table with teacher names and students I can put this in a subform and filter by teacher name so I have a list of her students in a sub form. the problem I have is this is created in...
1
5079
by: Bllich | last post by:
can anyone post an algoritam for the deepest level of a treeView ? it should be a recursive function I think.. I don't need treeView.Nodes.Level because my users don't select the nodes... I...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.