XML to CSV with missing attributes

A discussion of how to use EasyPatterns, EasyPattern Helper and using the EasyPattern library.

Moderator: DataMystic Support

User avatar
Fixer
Posts: 22
Joined: Thu Jul 31, 2008 6:39 am
Location: European Union > Poland
Contact:

XML to CSV with missing attributes

Postby Fixer » Mon Nov 24, 2008 10:20 am

How to convert XML to CSV when sometimes we have a missing attributes (param2, param3)?

input xml file

Code: Select all

<?xml version='1.0' encoding='iso-8859-2'?>
<details>
  <item param1="123" param2="321" param3="TWOFIL"/>
  <item param1="456" param2="534"/>
  <item param1="789" param3="GTREW"/>
  ...
</details>


output csv format:

Code: Select all

123;321;TWOFIL
456;534;;
789;;GTREW

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: XML to CSV with missing attributes

Postby DataMystic Support » Tue Nov 25, 2008 9:30 am

Use an optional perl pattern

Code: Select all

(param3="(.*)")?


or an optional EasyPattern:

Code: Select all

[ optional( 'param3="', capture(1+chars), '"') ]
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

User avatar
Fixer
Posts: 22
Joined: Thu Jul 31, 2008 6:39 am
Location: European Union > Poland
Contact:

Re: XML to CSV with missing attributes

Postby Fixer » Tue Nov 25, 2008 7:36 pm

thx it works :)


Return to “EasyPatterns Support”

Who is online

Users browsing this forum: No registered users and 2 guests