ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Just wondering if there are any tools available for doing this. I found CSV to XML but not the other way around. Basically I have the following structure:
<Level Grade=1>
<Content Step=A>Romero</Content>
<Content Step=B>Julie</Content>
<Content Step=C>Stephen</Content>
</Level>
<Level Grade=2>
<Content Step=A>Thomas</Content>
</Level>
<Level Grade=3>
<Content Step=A>Mary</Content>
<Content Step=B>Flora</Content>
<Content Step=C>Michael</Content>
<Content Step=D>Jerry</Content>
</Level>
And I want it to appear into the following structure:
Level, Content A, Content B, Content C, Content D
1, Romero, Julie, Stephen
2, Thomas, ,
3, Mary, Flora, Michael, Jerry
Just wondering if there are any tools available for doing this. I found CSV to XML but not the other way around. Basically I have the following structure:
<Level Grade=1>
<Content Step=A>Romero</Content>
<Content Step=B>Julie</Content>
<Content Step=C>Stephen</Content>
</Level>
<Level Grade=2>
<Content Step=A>Thomas</Content>
</Level>
<Level Grade=3>
<Content Step=A>Mary</Content>
<Content Step=B>Flora</Content>
<Content Step=C>Michael</Content>
<Content Step=D>Jerry</Content>
</Level>
And I want it to appear into the following structure:
Level, Content A, Content B, Content C, Content D
1, Romero, Julie, Stephen
2, Thomas, ,
3, Mary, Flora, Michael, Jerry
Any ideas?
Yes, grab a Perl module parsing XML and grab a Perl module generating CSV and glue them together.
Now I know Sergei is going to beat me about the head and ears, but I just thought I would put up an alternative to Tinkster's
as a learning solution for parsing files in general (although acknowledge not solely the best way top approach this):
Now I know Sergei is going to beat me about the head and ears, but I just thought I would put up an alternative to Tinkster's
as a learning solution for parsing files in general (although acknowledge not solely the best way top approach this):
@Tinkster - I have removed the trailing commas, but the headers would take some more work
Folks, I've seen too many production environment failures because of "childish" parsers. Childishness is assuming certain line oriented-ness when the language does not impose it.
The only legitimate cases to write "childish" parsers is when their input is generated automatically and the one who writes the parser can guarantee the input format won't change.
Folks, I've seen too many production environment failures because of "childish" parsers. Childishness is assuming certain line oriented-ness when the language does not impose it.
The only legitimate cases to write "childish" parsers is when their input is generated automatically and the one who writes the parser can guarantee the input format won't change.
First, thanks for the responses. Questions:
Sergei, can you show me some examples (maybe online) of these Perl modules? I don't know anything about them, and definitely nothing about gluing modules together.
knudfl, thanks for the link on the xml2csv java binary. Can you tell me where you found the way to input that command? I looked over the Sourceforge site but didn't find any documentation. Do they have both Windows and Linux versions?
First, thanks for the responses. Questions:
Sergei, can you show me some examples (maybe online) of these Perl modules? I don't know anything about them, and definitely nothing about gluing modules together.
knudfl, thanks for the link on the xml2csv java binary. Can you tell me where you found the way to input that command? I looked over the Sourceforge site but didn't find any documentation. Do they have both Windows and Linux versions?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.