473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XML to Text file

Hi friends,
My problem is very simple. But I really need you help. I want to convert an XML file into plaintext format. e.g; I have following contents in XML file :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  3. <!DOCTYPE persons SYSTEM "http://mail.persistent.co.in/v1/addrbook.dtd">
  4. <persons count="13"> 
  5. <person ref="6024732a-1c38-102a-922a-0007e9315819">
  6. <cn>Satish Agrawal</cn>
  7. <category unfiled="yes">3</category>
  8. <primaryphone>telephonenumber</primaryphone>
  9. <uuid>6024732a-1c38-102a-922a-0007e9315819</uuid>
  10. <lastmodtime>20060118T063535Z</lastmodtime>
  11. <surname>Agrawal</surname>
  12. <givenname>Satish</givenname>
  13. <mail>satishgrawal@persistent.co.in</mail>
  14. <telephonenumber primary="yes"/>
  15. <nickname>satish</nickname>
  16. <displayname>Satish Agrawal</displayname>
  17. </person>
  18. <person ref="0dbb27fa-20ed-102a-9922-0007e9315819">
  19. <cn>Rahul Patil</cn>
  20. <category unfiled="yes">3</category>
  21. <primaryphone>telephonenumber</primaryphone>
  22. <uuid>0dbb27fa-20ed-102a-9922-0007e9315819</uuid>
  23. <lastmodtime>20060124T061900Z</lastmodtime>
  24. <surname>Patil</surname>
  25. <givenname>Rahul</givenname>
  26. <mail>rahulptil@persistent.co.in</mail>
  27. <telephonenumber primary="yes"/>
  28. <nickname>rahul</nickname>
  29. <displayname>Rahul Patil</displayname>
  30. </person>
  31. <person ref="d141cc6e-20fd-102a-8307-0007e9315819">
  32. <cn>Milind Limaye</cn>
  33. <category unfiled="yes">3</category>
  34. <primaryphone>telephonenumber</primaryphone>
  35. <uuid>d141cc6e-20fd-102a-8307-0007e9315819</uuid>
  36. <lastmodtime>20060124T081900Z</lastmodtime>
  37. <surname>Limaye</surname>
  38. <givenname>Milind</givenname>
  39. <mail>milindaye@persistent.co.in</mail>
  40. <telephonenumber primary="yes"/>
  41. <nickname>milind</nickname>
  42. <displayname>Milind Limaye</displayname>
  43. </person>
  44. <person ref="b620b9c4-2669-102a-929b-0007e9315819">
  45. <cn>prerana</cn>
  46. <category>2</category>
  47. <primaryphone>telephonenumber</primaryphone>
  48. <uuid>b620b9c4-2669-102a-929b-0007e9315819</uuid>
  49. <lastmodtime>20060131T055356Z</lastmodtime>
  50. <surname>khare</surname>
  51. <givenname>prerana</givenname>
  52. <mail>preranhare@persistent.co.in</mail>
  53. <telephonenumber primary="yes"/>
  54. <nickname>prerana</nickname>
  55. <displayname>prerana</displayname>
  56. </person>
  57. </persons>
  58.  
And I want the outputs in following format (For each record ) :

Person 1:
Name : Satish Agrawal
Surname : Agrawal
UUID : 6024732a-1c38-102a-922a-0007e9315819
E mail : satishgrwal@persistent.co.in

and so on ...

Please suggest me what should I use. I have tried libwww and libxml libraries, but could not find much. Please guide.
Thanks.
May 26 '06 #1
1 3292
Use XSLT which converts XML into CSV or TXT format using XSL.
I guess , this should resolve u'r problem.




Hi friends,
My problem is very simple. But I really need you help. I want to convert an XML file into plaintext format. e.g; I have following contents in XML file :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  3. <!DOCTYPE persons SYSTEM "http://mail.persistent.co.in/v1/addrbook.dtd">
  4. <persons count="13"> 
  5. <person ref="6024732a-1c38-102a-922a-0007e9315819">
  6. <cn>Satish Agrawal</cn>
  7. <category unfiled="yes">3</category>
  8. <primaryphone>telephonenumber</primaryphone>
  9. <uuid>6024732a-1c38-102a-922a-0007e9315819</uuid>
  10. <lastmodtime>20060118T063535Z</lastmodtime>
  11. <surname>Agrawal</surname>
  12. <givenname>Satish</givenname>
  13. <mail>satishgrawal@persistent.co.in</mail>
  14. <telephonenumber primary="yes"/>
  15. <nickname>satish</nickname>
  16. <displayname>Satish Agrawal</displayname>
  17. </person>
  18. <person ref="0dbb27fa-20ed-102a-9922-0007e9315819">
  19. <cn>Rahul Patil</cn>
  20. <category unfiled="yes">3</category>
  21. <primaryphone>telephonenumber</primaryphone>
  22. <uuid>0dbb27fa-20ed-102a-9922-0007e9315819</uuid>
  23. <lastmodtime>20060124T061900Z</lastmodtime>
  24. <surname>Patil</surname>
  25. <givenname>Rahul</givenname>
  26. <mail>rahulptil@persistent.co.in</mail>
  27. <telephonenumber primary="yes"/>
  28. <nickname>rahul</nickname>
  29. <displayname>Rahul Patil</displayname>
  30. </person>
  31. <person ref="d141cc6e-20fd-102a-8307-0007e9315819">
  32. <cn>Milind Limaye</cn>
  33. <category unfiled="yes">3</category>
  34. <primaryphone>telephonenumber</primaryphone>
  35. <uuid>d141cc6e-20fd-102a-8307-0007e9315819</uuid>
  36. <lastmodtime>20060124T081900Z</lastmodtime>
  37. <surname>Limaye</surname>
  38. <givenname>Milind</givenname>
  39. <mail>milindaye@persistent.co.in</mail>
  40. <telephonenumber primary="yes"/>
  41. <nickname>milind</nickname>
  42. <displayname>Milind Limaye</displayname>
  43. </person>
  44. <person ref="b620b9c4-2669-102a-929b-0007e9315819">
  45. <cn>prerana</cn>
  46. <category>2</category>
  47. <primaryphone>telephonenumber</primaryphone>
  48. <uuid>b620b9c4-2669-102a-929b-0007e9315819</uuid>
  49. <lastmodtime>20060131T055356Z</lastmodtime>
  50. <surname>khare</surname>
  51. <givenname>prerana</givenname>
  52. <mail>preranhare@persistent.co.in</mail>
  53. <telephonenumber primary="yes"/>
  54. <nickname>prerana</nickname>
  55. <displayname>prerana</displayname>
  56. </person>
  57. </persons>
  58.  
And I want the outputs in following format (For each record ) :

Person 1:
Name : Satish Agrawal
Surname : Agrawal
UUID : 6024732a-1c38-102a-922a-0007e9315819
E mail : satishgrwal@persistent.co.in

and so on ...

Please suggest me what should I use. I have tried libwww and libxml libraries, but could not find much. Please guide.
Thanks.
May 21 '07 #2

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

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
1
by: Rigga | last post by:
Hi, I am new to Python and need to parse a text file and cut parts out i.e. say the text file contained 5 rows of text: line 1 of the text file line 2 of the text file line 3 of the text...
27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
16
by: thenightfly | last post by:
Ok, I know all about how binary numbers translate into text characters. My question is what exactly IS a text character? Is it a bitmap?
7
by: Chris | last post by:
Hi I can use a text file as a datasource but am unable to get the datatable to see the text file as having multiple columns. Everything gets put into the first column in the datatable. Sample of...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
10
by: bluemountain | last post by:
Hi there, Iam new to python forms and programming too I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2,...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.