Examples |
The following examples are used to illustrate some of the functionality of xmlfy.
In this example the input to xmlfy will come from the Solaris 10 /etc/passwd file and will look as follows:
root:x:0:0:Super-User:/:/sbin/sh bin:x:2:2::/usr/bin: guest:x:501:513:Guest user:/home/guest:/bin/rsh ag:x:600:602:Arthur Gouros:/home/ag:/bin/bash webdav:*LK*:701:703:Web Dav user:/etc/webdav:/bin/false
Create the following DTD file and save to /usr/share/schemata/solaris/passwd.dtd
<!ELEMENT passwordfile (user*)> <!ELEMENT user (name, pw, uid, gid, fullname?, home?, shell?)> <!ELEMENT name (#PCDATA)> <!ELEMENT pw (#PCDATA)> <!ELEMENT uid (#PCDATA)> <!ELEMENT gid (#PCDATA)> <!ELEMENT fullname (#PCDATA)> <!ELEMENT home (#PCDATA)> <!ELEMENT shell (#PCDATA)>
The output using a custom DTD and colon as the field delimiter:
% cat /etc/passwd | xmlfy -S /usr/share/schemata/solaris/passwd.dtd -F : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE passwordfile SYSTEM "/usr/share/schemata/solaris/passwd.dtd"> <passwordfile> <user> <name>root</name> <pw>x</pw> <uid>0</uid> <gid>0</gid> <fullname>Super-User</fullname> <home>/</home> <shell>/sbin/sh</shell> </user> <user> <name>bin</name> <pw>x</pw> <uid>2</uid> <gid>2</gid> <fullname></fullname> <home>/usr/bin</home> <shell></shell> </user> <user> <name>guest</name> <pw>x</pw> <uid>501</uid> <gid>513</gid> <fullname>Guest user</fullname> <home>/home/guest</home> <shell>/bin/rsh</shell> </user> <user> <name>ag</name> <pw>x</pw> <uid>600</uid> <gid>602</gid> <fullname>Arthur Gouros</fullname> <home>/home/ag</home> <shell>/bin/bash</shell> </user> <user> <name>webdav</name> <pw>*LK*</pw> <uid>701</uid> <gid>703</gid> <fullname>Web Dav user</fullname> <home>/etc/webdav</home> <shell>/bin/false</shell> </user> </passwordfile>
NOTE: By default xmlfy treats consecutive field delimiters (whitespace) as one field delimiter, but by specifying the -F option then this is turned off and zero length fields are allowed. If this was not the case then for the user bin the value for <home> will end up in the <fullname> field which is what we are telling xmlfy to do in the DTD file - but it is wrong. If there were spaces or values between the colons then this would produce the expected result but that is not the case here so we are forced to accept zero length fields as valid which is the expected behaviour.
In this example the input to xmlfy will come from the Solaris 10 ps -f command and will look as follows:
UID PID PPID C STIME TTY TIME CMD root 683 680 0 11:41:26 pts/4 0:00 bash root 763 683 0 12:00:54 pts/4 0:00 ps -f
% ps -f | xmlfy <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line> <field>UID</field> <field>PID</field> <field>PPID</field> <field>C</field> <field>STIME</field> <field>TTY</field> <field>TIME</field> <field>CMD</field> </line> <line> <field>root</field> <field>683</field> <field>680</field> <field>0</field> <field>11:41:26</field> <field>pts/4</field> <field>0:00</field> <field>bash</field> </line> <line> <field>root</field> <field>763</field> <field>683</field> <field>0</field> <field>12:00:54</field> <field>pts/4</field> <field>0:00</field> <field>ps</field> <field>-f</field> </line> </xmlfy>
% ps -f | xmlfy -l -f <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line1> <field1>UID</field1> <field2>PID</field2> <field3>PPID</field3> <field4>C</field4> <field5>STIME</field5> <field6>TTY</field6> <field7>TIME</field7> <field8>CMD</field8> </line1> <line2> <field1>root</field1> <field2>683</field2> <field3>680</field3> <field4>0</field4> <field5>11:41:26</field5> <field6>pts/4</field6> <field7>0:00</field7> <field8>bash</field8> </line2> <line3> <field1>root</field1> <field2>763</field2> <field3>683</field3> <field4>0</field4> <field5>12:00:54</field5> <field6>pts/4</field6> <field7>0:00</field7> <field8>ps</field8> <field9>-f</field9> </line3> </xmlfy>
The DTD file /usr/share/schemata/solaris/ps.dtd:
<!ELEMENT ps (heading), (process*)> <!ELEMENT heading (uid, pid, ppid, c, stime, tty, time, command)> <!ELEMENT process (uid, pid, ppid, c, stime, tty, time, command, arg*)> <!ELEMENT uid (#PCDATA)> <!ELEMENT pid (#PCDATA)> <!ELEMENT ppid (#PCDATA)> <!ELEMENT c (#PCDATA)> <!ELEMENT stime (#PCDATA)> <!ELEMENT tty (#PCDATA)> <!ELEMENT time (#PCDATA)> <!ELEMENT command (#PCDATA)> <!ELEMENT arg (#PCDATA)>
The output using this custom DTD file:
% ps -f | xmlfy -S /usr/share/schemata/solaris/ps.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ps SYSTEM "/usr/share/schemata/solaris/ps.dtd"> <ps> <heading> <uid>UID</uid> <pid>PID</pid> <ppid>PPID</ppid> <c>C</c> <stime>STIME</stime> <tty>TTY</tty> <time>TIME</time> <command>CMD</command> </heading> <process> <uid>root</uid> <pid>683</pid> <ppid>680</ppid> <c>0</c> <stime>11:41:26</stime> <tty>pts/4</tty> <time>0:00</time> <command>bash</command> </process> <process> <uid>root</uid> <pid>763</pid> <ppid>683</ppid> <c>0</c> <stime>12:00:54</stime> <tty>pts/4</tty> <time>0:00</time> <command>ps</command> <arg>-f</arg> </process> </ps>
The DTD file /usr/share/schemata/solaris/ps_multitree.dtd:
<!ELEMENT ps (heading), (process*)> <!ELEMENT heading (p, p, p, p, p, p, p, p)> <!ELEMENT process (uid, pid, ppid, c, stime, tty, time, command, arg*)> <!ELEMENT stime (hours, minutes, seconds)> <!ELEMENT time (minutes, seconds)> <!ELEMENT p (#PCDATA)> <!ELEMENT uid (#PCDATA)> <!ELEMENT pid (#PCDATA)> <!ELEMENT ppid (#PCDATA)> <!ELEMENT c (#PCDATA)> <!ELEMENT tty (#PCDATA)> <!ELEMENT command (#PCDATA)> <!ELEMENT arg (#PCDATA)> <!ELEMENT hours (#PCDATA)> <!ELEMENT minutes (#PCDATA)> <!ELEMENT seconds (#PCDATA)>
The output using this custom DTD file:
% ps -f | xmlfy -S /usr/share/schemata/solaris/ps_multitree.dtd -F3 : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ps SYSTEM "/usr/share/schemata/solaris/ps_multitree.dtd"> <ps> <heading> <p>UID</p> <p>PID</p> <p>PPID</p> <p>C</p> <p>STIME</p> <p>TTY</p> <p>TIME</p> <p>CMD</p> </heading> <process> <uid>root</uid> <pid>683</pid> <ppid>680</ppid> <c>0</c> <stime> <hours>11</hours> <minutes>41</minutes> <seconds>26</seconds> </stime> <tty>pts/4</tty> <time> <minutes>0</minutes> <seconds>00</seconds> </time> <command>bash</command> </process> <process> <uid>root</uid> <pid>763</pid> <ppid>683</ppid> <c>0</c> <stime> <hours>12</hours> <minutes>00</minutes> <seconds>54</seconds> </stime> <tty>pts/4</tty> <time> <minutes>0</minutes> <seconds>00</seconds> </time> <command>ps</command> <arg>-f</arg> </process> </ps>
In this example the input to xmlfy will come from SAMBA's smb.conf configuration file and will look as follows:
[global] workgroup = MYGROUP server string = Samba Server printcap name = /etc/printcap load printers = yes cups options = raw log file = /var/log/samba/%m.log max log size = 50 security = user socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 dns proxy = no idmap uid = 16777216-33554431 idmap gid = 16777216-33554431 template shell = /bin/false winbind use default domain = no [homes] comment = Home Directories browseable = no writable = yes [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes
Option -k turns on the key/value pairing functionality causing the first valid field of each new XML level to become the tag name. This is achieved by choosing the delimiters carefully and breaking the original structure into its relevant XML levels. This can be easily visualised by turning off the -k option and examining the field order in the XML tree hierarchy.
The field separator option -F3:1 '=' is scoped to only act on the first occurance of delimiter string "=" and treat any further occurances at this level as data.
% cat smb.conf | xmlfy -k -F1 '[' -F2 ']' -F2 '\n' -F3:1 '=' -t -T0 name smb-conf <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE smb-conf SYSTEM "xmlfy.dtd"> <smb-conf> <global> <workgroup>MYGROUP</workgroup> <server_string>Samba Server</server_string> <printcap_name>/etc/printcap</printcap_name> <load_printers>yes</load_printers> <cups_options>raw</cups_options> <log_file>/var/log/samba/%m.log</log_file> <max_log_size>50</max_log_size> <security>user</security> <socket_options>TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192</socket_options> <dns_proxy>no</dns_proxy> <idmap_uid>16777216-33554431</idmap_uid> <idmap_gid>16777216-33554431</idmap_gid> <template_shell>/bin/false</template_shell> <winbind_use_default_domain>no</winbind_use_default_domain> </global> <homes> <comment>Home Directories</comment> <browseable>no</browseable> <writable>yes</writable> </homes> <printers> <comment>All Printers</comment> <path>/var/spool/samba</path> <browseable>no</browseable> <guest_ok>no</guest_ok> <writable>no</writable> <printable>yes</printable> </printers> </smb-conf>
In this example the input to xmlfy will come from a data.csv file and will look as follows:
"Nov release (Drop0) 30/11/2006",Source Lines,Total Files,"Delta Source","Delta Files" SDP_CORE_2.1,15945,283,-247,-52 SDP_STREAMING_MGR_2.1,6863,473,-2228,-232 SMI_CDS_Connecter_OnlineCharging_2.1,2590,13,240,2 SMI_CDS_Connecter_ContentInfo_2.1,789,13,66,2 SDP_WEBPORTAL_FOH_2.1,19632,547,209,-14 SDP_AUDITSERVER_2.1,6532,142,1573,46 SDP_WAPPORTAL_MCP_2.1,23100,756,5676,53 SDP_CMS2_CPP_2.0,14614,440,0,0 SDP_CMS2_DOCAPPS_2.0,0,1120,0,7 SDP_CMS2_INGESTION_2.0,3742,98,0,0 SDP_CMS2_SERVERSIDE_2.0,7350,86,702,7 SDP_WAPPORTAL_3G,0,0,-5096,-617 SDP_WAPPORTAL_2.5G_1.2,7923,834,14,-10 SDP_MADEVICEDB_2.0,0,7,0,2 SDP_WAPE_1.3,0,398,0,0 SMI_CDS_Connecter_UrlReWriter_2.1,698,13,698,13 SDP_BASE_COMMON_2.1,1427,49,1427,49 SDP_COMMON_SERVICES_2.1,1336,57,1336,57 SDP_ADAPTOR_CD_2.1,923,84,923,84 SDP_ADAPTOR_EMM_2.1,2429,68,2429,68 SDP_ADAPTOR_ESS_2.1,10581,247,10581,247 SDP_ADAPTOR_USIS_2.1,2464,85,2464,85 SDP_BS_ALERT_SERVICE_2.1,754,30,754,30 SDP_BS_CHARGING_SERVICE_2.1,462,23,462,23 SDP_BS_COMMON_SERVICE_2.1,5012,95,5012,95 SDP_BS_CONTENT_SERVICE_2.1,1910,63,1910,63 SDP_BS_DEVICE_SERVICE_2.1,1039,33,1039,33 SDP_BS_SUBSCRIPTION_OFFER_SERVICE_2.1,4408,61,4408,61 SDP_BS_SUBSCRIPTION_SERVICE_2.1,8087,95,8087,95 SDP_BS_TRANSACTION_MGMT_SERVICE_2.1,5393,57,5393,57 SDP_BS_URL_GENERATOR_SERVICE_2.1,484,20,484,20 SDP_BS_USER_SERVICE_2.1,407,17,407,17 SDP_BS_VALIDATION_SERVICE_2.1,8473,100,8473,100 SDP_TWSI_2.1,12021,123,12021,123 SDP_URL_REDIRECTOR_2.1,332,16,332,16 SDP_TEST_CLIENTS_2.1,7191,687,7191,687 Total,177720,6546,69549,530
In this example we convert the CSV file to XML with just a few simple options.
% cat data.csv | xmlfy -F2 , -q -t <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line> <field>Nov release (Drop0) 30/11/2006</field> <field>Source Lines</field> <field>Total Files</field> <field>Delta Source</field> <field>Delta Files</field> </line> <line> <field>SDP_CORE_2.1</field> <field>15945</field> <field>283</field> <field>-247</field> <field>-52</field> </line> <line> <field>SDP_STREAMING_MGR_2.1</field> <field>6863</field> <field>473</field> <field>-2228</field> <field>-232</field> </line> <line> <field>SMI_CDS_Connecter_OnlineCharging_2.1</field> <field>2590</field> <field>13</field> <field>240</field> <field>2</field> </line> <line> <field>SMI_CDS_Connecter_ContentInfo_2.1</field> <field>789</field> <field>13</field> <field>66</field> <field>2</field> </line> <line> <field>SDP_WEBPORTAL_FOH_2.1</field> <field>19632</field> <field>547</field> <field>209</field> <field>-14</field> </line> <line> <field>SDP_AUDITSERVER_2.1</field> <field>6532</field> <field>142</field> <field>1573</field> <field>46</field> </line> <line> <field>SDP_WAPPORTAL_MCP_2.13</field> <field>23100</field> <field>756</field> <field>5676</field> <field>53</field> </line> <line> <field>SDP_CMS2_CPP_2.0</field> <field>14614</field> <field>440</field> <field>0</field> <field>0</field> </line> <line> <field>SDP_CMS2_DOCAPPS_2.0</field> <field>0</field> <field>1120</field> <field>0</field> <field>7</field> </line> <line> <field>SDP_CMS2_INGESTION_2.0</field> <field>3742</field> <field>98</field> <field>0</field> <field>0</field> </line> <line> <field>SDP_CMS2_SERVERSIDE_2.0</field> <field>7350</field> <field>86</field> <field>702</field> <field>7</field> </line> <line> <field>SDP_WAPPORTAL_3G</field> <field>0</field> <field>0</field> <field>-5096</field> <field>-617</field> </line> <line> <field>SDP_WAPPORTAL_2.5G_1.2</field> <field>7923</field> <field>834</field> <field>14</field> <field>-10</field> </line> <line> <field>SDP_MADEVICEDB_2.0</field> <field>0</field> <field>7</field> <field>0</field> <field>2</field> </line> <line> <field>SDP_WAPE_1.3</field> <field>0</field> <field>398</field> <field>0</field> <field>0</field> </line> <line> <field>SMI_CDS_Connecter_UrlReWriter_2.1</field> <field>698</field> <field>13</field> <field>698</field> <field>13</field> </line> <line> <field>SDP_BASE_COMMON_2.1</field> <field>1427</field> <field>49</field> <field>1427</field> <field>49</field> </line> <line> <field>SDP_COMMON_SERVICES_2.1</field> <field>1336</field> <field>57</field> <field>1336</field> <field>57</field> </line> <line> <field>SDP_ADAPTOR_CD_2.1</field> <field>923</field> <field>84</field> <field>923</field> <field>84</field> </line> <line> <field>SDP_ADAPTOR_EMM_2.1</field> <field>2429</field> <field>68</field> <field>2429</field> <field>68</field> </line> <line> <field>SDP_ADAPTOR_ESS_2.1</field> <field>10581</field> <field>247</field> <field>10581</field> <field>247</field> </line> <line> <field>SDP_ADAPTOR_USIS_2.1</field> <field>2464</field> <field>85</field> <field>2464</field> <field>85</field> </line> <line> <field>SDP_BS_ALERT_SERVICE_2.1</field> <field>754</field> <field>30</field> <field>754</field> <field>30</field> </line> <line> <field>SDP_BS_CHARGING_SERVICE_2.1</field> <field>462</field> <field>23</field> <field>462</field> <field>23</field> </line> <line> <field>SDP_BS_COMMON_SERVICE_2.1</field> <field>5012</field> <field>95</field> <field>5012</field> <field>95</field> </line> <line> <field>SDP_BS_CONTENT_SERVICE_2.1</field> <field>1910</field> <field>63</field> <field>1910</field> <field>63</field> </line> <line> <field>SDP_BS_DEVICE_SERVICE_2.1</field> <field>1039</field> <field>33</field> <field>1039</field> <field>33</field> </line> <line> <field>SDP_BS_SUBSCRIPTION_OFFER_SERVICE_2.1</field> <field>4408</field> <field>61</field> <field>4408</field> <field>61</field> </line> <line> <field>SDP_BS_SUBSCRIPTION_SERVICE_2.1</field> <field>8087</field> <field>95</field> <field>8087</field> <field>95</field> </line> <line> <field>SDP_BS_TRANSACTION_MGMT_SERVICE_2.1</field> <field>5393</field> <field>57</field> <field>5393</field> <field>57</field> </line> <line> <field>SDP_BS_URL_GENERATOR_SERVICE_2.1</field> <field>484</field> <field>20</field> <field>484</field> <field>20</field> </line> <line> <field>SDP_BS_USER_SERVICE_2.1</field> <field>407</field> <field>17</field> <field>407</field> <field>17</field> </line> <line> <field>SDP_BS_VALIDATION_SERVICE_2.1</field> <field>8473</field> <field>100</field> <field>8473</field> <field>100</field> </line> <line> <field>SDP_TWSI_2.1</field> <field>12021</field> <field>123</field> <field>12021</field> <field>123</field> </line> <line> <field>SDP_URL_REDIRECTOR_2.1</field> <field>332</field> <field>16</field> <field>332</field> <field>16</field> </line> <line> <field>SDP_TEST_CLIENTS_2.1</field> <field>7191</field> <field>687</field> <field>7191</field> <field>687</field> </line> <line> <field>Total</field> <field>177720</field> <field>6546</field> <field>69549</field> <field>530</field> </line> </xmlfy>
In this example we use a RNC schema file called schema.rnc that looks as follows:
## xmlfy-args: -E n1 -E f1/Total/ -F2 , -q -t start = release release = element release { component* } component = element component { cname, source_lines, total_files, delta_source, delta_files } cname = element cname { text } source_lines = element source_lines { text } total_files = element total_files { text } delta_source = element delta_source { text } delta_files = element delta_files { text }
Note that the schema file contains xmlfy arguments which are much the same as the previous example except that we expel the first and last input lines that were derived from spreadsheet titles.
The output looks as follows:
% cat data.csv | xmlfy -S schema.rnc <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE release SYSTEM "schema.rnc"> <release> <component> <cname>SDP_CORE_2.1</cname> <source_lines>15945</source_lines> <total_files>283</total_files> <delta_source>-247</delta_source> <delta_files>-52</delta_files> </component> <component> <cname>SDP_STREAMING_MGR_2.1</cname> <source_lines>6863</source_lines> <total_files>473</total_files> <delta_source>-2228</delta_source> <delta_files>-232</delta_files> </component> <component> <cname>SMI_CDS_Connecter_OnlineCharging_2.1</cname> <source_lines>2590</source_lines> <total_files>13</total_files> <delta_source>240</delta_source> <delta_files>2</delta_files> </component> <component> <cname>SMI_CDS_Connecter_ContentInfo_2.1</cname> <source_lines>789</source_lines> <total_files>13</total_files> <delta_source>66</delta_source> <delta_files>2</delta_files> </component> <component> <cname>SDP_WEBPORTAL_FOH_2.1</cname> <source_lines>19632</source_lines> <total_files>547</total_files> <delta_source>209</delta_source> <delta_files>-14</delta_files> </component> <component> <cname>SDP_AUDITSERVER_2.1</cname> <source_lines>6532</source_lines> <total_files>142</total_files> <delta_source>1573</delta_source> <delta_files>46</delta_files> </component> <component> <cname>SDP_WAPPORTAL_MCP_2.1</cname> <source_lines>23100</source_lines> <total_files>756</total_files> <delta_source>5676</delta_source> <delta_files>53</delta_files> </component> <component> <cname>SDP_CMS2_CPP_2.0</cname> <source_lines>14614</source_lines> <total_files>440</total_files> <delta_source>0</delta_source> <delta_files>0</delta_files> </component> <component> <cname>SDP_CMS2_DOCAPPS_2.0</cname> <source_lines>0</source_lines> <total_files>1120</total_files> <delta_source>0</delta_source> <delta_files>7</delta_files> </component> <component> <cname>SDP_CMS2_INGESTION_2.0</cname> <source_lines>3742</source_lines> <total_files>98</total_files> <delta_source>0</delta_source> <delta_files>0</delta_files> </component> <component> <cname>SDP_CMS2_SERVERSIDE_2.0</cname> <source_lines>7350</source_lines> <total_files>86</total_files> <delta_source>702</delta_source> <delta_files>7</delta_files> </component> <component> <cname>SDP_WAPPORTAL_3G</cname> <source_lines>0</source_lines> <total_files>0</total_files> <delta_source>-5096</delta_source> <delta_files>-617</delta_files> </component> <component> <cname>SDP_WAPPORTAL_2.5G_1.2</cname> <source_lines>7923</source_lines> <total_files>834</total_files> <delta_source>14</delta_source> <delta_files>-10</delta_files> </component> <component> <cname>SDP_MADEVICEDB_2.0</cname> <source_lines>0</source_lines> <total_files>7</total_files> <delta_source>0</delta_source> <delta_files>2</delta_files> </component> <component> <cname>SDP_WAPE_1.3</cname> <source_lines>0</source_lines> <total_files>398</total_files> <delta_source>0</delta_source> <delta_files>0</delta_files> </component> <component> <cname>SMI_CDS_Connecter_UrlReWriter_2.1</cname> <source_lines>698</source_lines> <total_files>13</total_files> <delta_source>698</delta_source> <delta_files>13</delta_files> </component> <component> <cname>SDP_BASE_COMMON_2.1</cname> <source_lines>1427</source_lines> <total_files>49</total_files> <delta_source>1427</delta_source> <delta_files>49</delta_files> </component> <component> <cname>SDP_COMMON_SERVICES_2.1</cname> <source_lines>1336</source_lines> <total_files>57</total_files> <delta_source>1336</delta_source> <delta_files>57</delta_files> </component> <component> <cname>SDP_ADAPTOR_CD_2.1</cname> <source_lines>923</source_lines> <total_files>84</total_files> <delta_source>923</delta_source> <delta_files>84</delta_files> </component> <component> <cname>SDP_ADAPTOR_EMM_2.1</cname> <source_lines>2429</source_lines> <total_files>68</total_files> <delta_source>2429</delta_source> <delta_files>68</delta_files> </component> <component> <cname>SDP_ADAPTOR_ESS_2.1</cname> <source_lines>10581</source_lines> <total_files>247</total_files> <delta_source>10581</delta_source> <delta_files>247</delta_files> </component> <component> <cname>SDP_ADAPTOR_USIS_2.1</cname> <source_lines>2464</source_lines> <total_files>85</total_files> <delta_source>2464</delta_source> <delta_files>85</delta_files> </component> <component> <cname>SDP_BS_ALERT_SERVICE_2.1</cname> <source_lines>754</source_lines> <total_files>30</total_files> <delta_source>754</delta_source> <delta_files>30</delta_files> </component> <component> <cname>SDP_BS_CHARGING_SERVICE_2.1</cname> <source_lines>462</source_lines> <total_files>23</total_files> <delta_source>462</delta_source> <delta_files>23</delta_files> </component> <component> <cname>SDP_BS_COMMON_SERVICE_2.1</cname> <source_lines>5012</source_lines> <total_files>95</total_files> <delta_source>5012</delta_source> <delta_files>95</delta_files> </component> <component> <cname>SDP_BS_CONTENT_SERVICE_2.1</cname> <source_lines>1910</source_lines> <total_files>63</total_files> <delta_source>1910</delta_source> <delta_files>63</delta_files> </component> <component> <cname>SDP_BS_DEVICE_SERVICE_2.1</cname> <source_lines>1039</source_lines> <total_files>33</total_files> <delta_source>1039</delta_source> <delta_files>33</delta_files> </component> <component> <cname>SDP_BS_SUBSCRIPTION_OFFER_SERVICE_2.1</cname> <source_lines>4408</source_lines> <total_files>61</total_files> <delta_source>4408</delta_source> <delta_files>61</delta_files> </component> <component> <cname>SDP_BS_SUBSCRIPTION_SERVICE_2.1</cname> <source_lines>8087</source_lines> <total_files>95</total_files> <delta_source>8087</delta_source> <delta_files>95</delta_files> </component> <component> <cname>SDP_BS_TRANSACTION_MGMT_SERVICE_2.1</cname> <source_lines>5393</source_lines> <total_files>57</total_files> <delta_source>5393</delta_source> <delta_files>57</delta_files> </component> <component> <cname>SDP_BS_URL_GENERATOR_SERVICE_2.1</cname> <source_lines>484</source_lines> <total_files>20</total_files> <delta_source>484</delta_source> <delta_files>20</delta_files> </component> <component> <cname>SDP_BS_USER_SERVICE_2.1</cname> <source_lines>407</source_lines> <total_files>17</total_files> <delta_source>407</delta_source> <delta_files>17</delta_files> </component> <component> <cname>SDP_BS_VALIDATION_SERVICE_2.1</cname> <source_lines>8473</source_lines> <total_files>100</total_files> <delta_source>8473</delta_source> <delta_files>100</delta_files> </component> <component> <cname>SDP_TWSI_2.1</cname> <source_lines>12021</source_lines> <total_files>123</total_files> <delta_source>12021</delta_source> <delta_files>123</delta_files> </component> <component> <cname>SDP_URL_REDIRECTOR_2.1</cname> <source_lines>332</source_lines> <total_files>16</total_files> <delta_source>332</delta_source> <delta_files>16</delta_files> </component> <component> <cname>SDP_TEST_CLIENTS_2.1</cname> <source_lines>7191</source_lines> <total_files>687</total_files> <delta_source>7191</delta_source> <delta_files>687</delta_files> </component> </release>
In this example the input to xmlfy will come from Windows's WIN.INI configuration file and will look as follows:
; for 16-bit app support [fonts] [extensions] [mci extensions] [files] [Mail] MAPI=1 CMCDLLNAME32=mapi32.dll CMCDLLNAME=mapi.dll CMC=1 MAPIX=1 MAPIXVER=1.0.0.1 OLEMessaging=1 [MCI Extensions.BAK] aif=MPEGVideo aifc=MPEGVideo aiff=MPEGVideo asf=MPEGVideo asx=MPEGVideo au=MPEGVideo m1v=MPEGVideo m3u=MPEGVideo mp2=MPEGVideo mp2v=MPEGVideo mp3=MPEGVideo mpa=MPEGVideo mpe=MPEGVideo mpeg=MPEGVideo mpg=MPEGVideo mpv2=MPEGVideo snd=MPEGVideo wax=MPEGVideo wm=MPEGVideo wma=MPEGVideo wmv=MPEGVideo wmx=MPEGVideo wpl=MPEGVideo wvx=MPEGVideo [WinZip] Note-1=This section is required only to install the optional WinZip Internet Browser Support build 0231. Note-2=Removing this section of the win.ini will have no effect except preventing installation of WinZip Internet Browser Support build 0231. win32_version=R6.3-7.0 [IRIS_IPE] menu=1 [Readiris] Scanner32=Twaino38,23 [SciCalc] layout=0 [Intel] CurrentLanguage=enu [DarkBasicStateData] BEST3DCARD=Primary Display Driver BEST3DDEPTH=16
Option -E 'c1-1/;/' expels any INI comments from the input.
Option -k turns on the key/value pairing functionality causing the first valid field of each new XML level to become the tag name. This is achieved by choosing the delimiters carefully and breaking the original structure into its relevant XML levels. This can be easily visualised by turning off the -k option and examining the field order in the XML tree hierarchy.
The field separator option -F3:1 '=' is scoped to only act on the first occurance of delimiter string "=" and treat any further occurances at this level as data.
% cat WIN.INI | xmlfy -E 'c1-1/;/' -k -F1 '[' -F2 ']' -F2 '\n' -F3:1 '=' -t -T0 name win-ini <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE win-ini SYSTEM "xmlfy.dtd"> <win-ini> <fonts> </fonts> <extensions> </extensions> <mci_extensions> </mci_extensions> <files> </files> <Mail> <MAPI>1</MAPI> <CMCDLLNAME32>mapi32.dll</CMCDLLNAME32> <CMCDLLNAME>mapi.dll</CMCDLLNAME> <CMC>1</CMC> <MAPIX>1</MAPIX> <MAPIXVER>1.0.0.1</MAPIXVER> <OLEMessaging>1</OLEMessaging> </Mail> <MCI_Extensions.BAK> <aif>MPEGVideo</aif> <aifc>MPEGVideo</aifc> <aiff>MPEGVideo</aiff> <asf>MPEGVideo</asf> <asx>MPEGVideo</asx> <au>MPEGVideo</au> <m1v>MPEGVideo</m1v> <m3u>MPEGVideo</m3u> <mp2>MPEGVideo</mp2> <mp2v>MPEGVideo</mp2v> <mp3>MPEGVideo</mp3> <mpa>MPEGVideo</mpa> <mpe>MPEGVideo</mpe> <mpeg>MPEGVideo</mpeg> <mpg>MPEGVideo</mpg> <mpv2>MPEGVideo</mpv2> <snd>MPEGVideo</snd> <wax>MPEGVideo</wax> <wm>MPEGVideo</wm> <wma>MPEGVideo</wma> <wmv>MPEGVideo</wmv> <wmx>MPEGVideo</wmx> <wpl>MPEGVideo</wpl> <wvx>MPEGVideo</wvx> </MCI_Extensions.BAK> <WinZip> <Note-1>This section is required only to install the optional WinZip Internet Browser Support build 0231.</Note-1> <Note-2>Removing this section of the win.ini will have no effect except preventing installation of WinZip Internet Browser Support build 0231.</Note-2> <win32_version>R6.3-7.0</win32_version> </WinZip> <IRIS_IPE> <menu>1</menu> </IRIS_IPE> <Readiris> <Scanner32>Twaino38,23</Scanner32> </Readiris> <SciCalc> <layout>0</layout> </SciCalc> <Intel> <CurrentLanguage>enu</CurrentLanguage> </Intel> <DarkBasicStateData> <BEST3DCARD>Primary Display Driver</BEST3DCARD> <BEST3DDEPTH>16</BEST3DDEPTH> </DarkBasicStateData> </win-ini>
In this example the entire input is captured as one input record, the first field which is a comment is expelled and key/value pairing only occurs with level 3 fields which are scoped.
% infocmp vt220 | xmlfy -F1 __ALL__ -F2 , -F3:1 '=' -E 'f1/#/:1' -k3 -T1 name vt220 -t <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <vt220> <field>am</field> <field>mc5i</field> <field>mir</field> <field>msgr</field> <field>xenl</field> <field>xon</field> <field>cols#80</field> <field>it#8</field> <field>lines#24</field> <field>vt#3</field> <acsc>``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{¦¦}}~~</acsc> <bel>^G</bel> <blink>\E[5m</blink> <bold>\E[1m</bold> <clear>\E[H\E[J</clear> <cr>^M</cr> <csr>\E[%i%p1%d;%p2%dr</csr> <cub>\E[%p1%dD</cub> <cub1>^H</cub1> <cud>\E[%p1%dB</cud> <cud1>^J</cud1> <cuf>\E[%p1%dC</cuf> <cuf1>\E[C</cuf1> <cup>\E[%i%p1%d;%p2%dH</cup> <cuu>\E[%p1%dA</cuu> <cuu1>\E[A</cuu1> <dch>\E[%p1%dP</dch> <dch1>\E[P</dch1> <dl>\E[%p1%dM</dl> <dl1>\E[M</dl1> <ech>\E[%p1%dX</ech> <ed>\E[J</ed> <el>\E[K</el> <el1>\E[1K</el1> <enacs>\E)0</enacs> <flash>\E[?5h$<200/>\E[?5l</flash> <home>\E[H</home> <ht>^I</ht> <hts>\EH</hts> <ich>\E[%p1%d@</ich> <if>/usr/share/tabset/vt100</if> <il>\E[%p1%dL</il> <il1>\E[L</il1> <ind>\ED</ind> <is2>\E[?7h\E[>\E[?1h\E F\E[?4l</is2> <kbs>^H</kbs> <kcub1>\E[D</kcub1> <kcud1>\E[B</kcud1> <kcuf1>\E[C</kcuf1> <kcuu1>\E[A</kcuu1> <kf1>\EOP</kf1> <kf10>\E[21~</kf10> <kf11>\E[23~</kf11> <kf12>\E[24~</kf12> <kf13>\E[25~</kf13> <kf14>\E[26~</kf14> <kf17>\E[31~</kf17> <kf18>\E[32~</kf18> <kf19>\E[33~</kf19> <kf2>\EOQ</kf2> <kf20>\E[34~</kf20> <kf3>\EOR</kf3> <kf4>\EOS</kf4> <kf6>\E[17~</kf6> <kf7>\E[18~</kf7> <kf8>\E[19~</kf8> <kf9>\E[20~</kf9> <kfnd>\E[1~</kfnd> <khlp>\E[28~</khlp> <kich1>\E[2~</kich1> <knp>\E[6~</knp> <kpp>\E[5~</kpp> <krdo>\E[29~</krdo> <kslt>\E[4~</kslt> <lf1>pf1</lf1> <lf2>pf2</lf2> <lf3>pf3</lf3> <lf4>pf4</lf4> <mc0>\E[i</mc0> <mc4>\E[4i</mc4> <mc5>\E[5i</mc5> <nel>\EE</nel> <rc>\E8</rc> <rev>\E[7m</rev> <ri>\EM</ri> <rmacs>\E(B$<4></rmacs> <rmam>\E[?7l</rmam> <rmir>\E[4l</rmir> <rmso>\E[27m</rmso> <rmul>\E[24m</rmul> <rs1>\E[?3l</rs1> <sc>\E7</sc> <sgr>\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%¦%t;7%;m%?%p9%t\E(0%e\E(B%;$<2></sgr> <sgr0>\E[m\E(B</sgr0> <smacs>\E(0$<2></smacs> <smam>\E[?7h</smam> <smir>\E[4h</smir> <smso>\E[7m</smso> <smul>\E[4m</smul> <tbc>\E[3g</tbc> </vt220> </xmlfy>
In this example we use a DTD schema to convert the Apache access_log file into XML format.
The DTD file /usr/share/schemata/access_log.dtd:
<!-- xmlfy-args: -q -Q '\"[]' -t --> <!ELEMENT access_log (entry*)> <!ELEMENT entry (remote_host, identd, remote_user, timestamp, request, status, size, referer, user_agent)> <!ELEMENT remote_host (#PCDATA)> <!ELEMENT identd (#PCDATA)> <!ELEMENT remote_user (#PCDATA)> <!ELEMENT timestamp (#PCDATA)> <!ELEMENT request (#PCDATA)> <!ELEMENT status (#PCDATA)> <!ELEMENT size (#PCDATA)> <!ELEMENT referer (#PCDATA)> <!ELEMENT user_agent (#PCDATA)>
The output using this DTD schema:
% cat /var/log/httpd/access_log | xmlfy -S /usr/share/schemata/access_log.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE access_log SYSTEM "/usr/share/schemata/access_log.dtd"> <access_log <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:44:56 +1100</timestamp> <request>GET /doc HTTP/1.1</request> <status>404</status> <size>276</size> <referer>-</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:44:56 +1100</timestamp> <request>GET /favicon.ico HTTP/1.1</request> <status>404</status> <size>284</size> <referer>-</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:44:59 +1100</timestamp> <request>GET /favicon.ico HTTP/1.1</request> <status>404</status> <size>284</size> <referer>-</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:00 +1100</timestamp> <request>GET /docs HTTP/1.1</request> <status>301</status> <size>305</size> <referer>-</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:00 +1100</timestamp> <request>GET /docs/ HTTP/1.1</request> <status>403</status> <size>282</size> <referer>-</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/ HTTP/1.1</request> <status>200</status> <size>7328</size> <referer>-</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/style/base.css HTTP/1.1</request> <status>200</status> <size>2280</size> <referer>http://localhost/docs/</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/style/theme.css HTTP/1.1</request> <status>200</status> <size>3238</size> <referer>http://localhost/docs/</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/style/print.css HTTP/1.1</request> <status>200</status> <size>207</size> <referer>http://localhost/docs/</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/images/xmlfy_logo.jpg HTTP/1.1</request> <status>200</status> <size>13076</size> <referer>http://localhost/docs/</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/images/howitworks.png HTTP/1.1</request> <status>200</status> <size>77617</size> <referer>http://localhost/docs/</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/images/external.png HTTP/1.1</request> <status>200</status> <size>206</size> <referer>http://localhost/docs/style/theme.css</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/images/bar_left_ximal.png HTTP/1.1</request> <status>200</status> <size>2800</size> <referer>http://localhost/docs/style/theme.css</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/images/bar_middle.png HTTP/1.1</request> <status>200</status> <size>283</size> <referer>http://localhost/docs/style/theme.css</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> <entry> <remote_host>127.0.0.1</remote_host> <identd>-</identd> <remote_user>-</remote_user> <timestamp>15/Nov/2009:07:45:28 +1100</timestamp> <request>GET /docs/images/bar_right.png HTTP/1.1</request> <status>200</status> <size>2126</size> <referer>http://localhost/docs/style/theme.css</referer> <user_agent>Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4) Gecko/20090427 Fedora/3.5-0.20.beta4.fc11 Firefox/3.5b4</user_agent> </entry> </access_log>
In this example we encapsulate command line output in a snippet of XML that looks like a HTML table.
The DTD file /usr/share/schemata/html_table.dtd:
<!-- xmlfy-args: -p rtagopen -p records -p rtagclose -A0 insert border 1 -A0 insert bgcolor #ffffcc --> <!ELEMENT table (tr*)> <!ELEMENT tr (td*)> <!ELEMENT td (#PCDATA)>
The output using this DTD schema:
% ps -f | xmlfy -S /usr/share/schemata/html_table.dtd <table border="1" bgcolor="#ffffcc"> <tr> <td>UID</td> <td>PID</td> <td>PPID</td> <td>C</td> <td>STIME</td> <td>TTY</td> <td>TIME</td> <td>CMD</td> </tr> <tr> <td>root</td> <td>683</td> <td>680</td> <td>0</td> <td>11:41:26</td> <td>pts/4</td> <td>0:00</td> <td>bash</td> </tr> <tr> <td>root</td> <td>763</td> <td>683</td> <td>0</td> <td>12:00:54</td> <td>pts/4</td> <td>0:00</td> <td>ps</td> <td>-f</td> </tr> </table>
The same output as interpreted by a web browser.
UID | PID | PPID | C | STIME | TTY | TIME | CMD | |
root | 683 | 680 | 0 | 11:41:26 | pts/4 | 0:00 | bash | |
root | 763 | 683 | 0 | 12:00:54 | pts/4 | 0:00 | ps | -f |
In this example the input to xmlfy will come from a data file called sentence.txt and will look as follows:
Word. Two words. Now three words. This is four words.
The DTD file /usr/share/schemata/solaris/sentence.dtd:
<!ELEMENT paragraph (sentence+)> <!ELEMENT sentence (startword, middleword*, endword)> <!ELEMENT startword (#PCDATA)> <!ELEMENT middleword (#PCDATA)> <!ELEMENT endword (#PCDATA)>
The output using this DTD schema and SOAP options:
% cat sentence.txt | xmlfy -S /usr/share/schemata/solaris/sentence.dtd -R . -X SOAP1.2 -T1 number <?xml version="1.0?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Header> <xh:xmlfyHeader xmlns:xh="http://xmlfy.sourceforge.net/soap-xmlfyHeader" env:mustUnderstand="false"> <xh:program>xmlfy</xh:program> <xh:version>1.5.1</xh:version> <xh:timestamp>1253671370</xh:timestamp> <xh:sed>hook</xh:sed> </xh:xmlfyHeader> </env:Header> <env:Body> <x:paragraph xmlns:x="http://xmlfy.sourceforge.net/soap-xmlfy" env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> <x:sentence1> <x:startword>Two</x:startword> <x:endword>words</x:endword> </x:sentence1> <x:sentence2> <x:startword>Now</x:startword> <x:middleword>three</x:middleword> <x:endword>words</x:endword> </x:sentence2> <x:sentence3> <x:startword>This</x:startword> <x:middleword>is</x:middleword> <x:middleword>four</x:middleword> <x:endword>words</x:endword> </x:sentence3> </x:paragraph> </env:Body> </env:Envelope>
In this example the input to xmlfy will come from a much handled XML file called passwd.xml and will look as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line> <field>admin</field> <field>use_crypt</field> <field>500</field> <field>544</field> <!-- BOFH --> <field>Administrator</field> <field>/home/admin</field> <field>/bin/bash</field> </line> <!-- old <line> <field>Ro</field> <field>use_crypt</field> <field>211</field> <field>544</field> <field>Ro</field> <field>/export/home/Ro</field> <field>/bin/sh</field> </line> </xmlfy --> <line> <field>Ro</field> <field></field> <field>649</field> <field>544</field> <field>"<Ro¦&Ro's>"</field> <field>/home/Ro</field> <field>/bin/bash</field> </line> </xmlfy> this line is orphaned data <xmlfy> <line> <field>al0</field> <field>*</field> <field>650</field> <field>777</field> <field><name>Another Level 0</name><ph>12345678</ph><loc>6th floor</loc></field> <field>/home/al0</field> <field>/bin/sh</field> </line> </xmlfy>
The output using the passwd.xml file:
% cat passwd.xml | xmlfy -U -F2 : -F3 ", " admin:use_crypt:500:544:Administrator:/home/admin:/bin/bash Ro::649:544:"<Ro¦&Ro's>":/home/Ro:/bin/bash al0:*:650:777:Another Level 0, 12345678, 6th floor:/home/al0:/bin/sh
NOTE: If you view the page source of this example you will see that it has been manually treated for HTML presentation. This extra step is required because the undo XML option also restores escaped HTML characters. E.g. "<" becomes "<".
The undo XML command can also be applied to HTML or XHTML files to strip out meta-data and leave behind just the raw text. The command to do this would look similar as follows:
% cat index.html | xmlfy -U -F2 "\n" -F3 "\n" -F4 "\n"
The four delimiter levels specified in this example are arbitrary and dependant on the HTML complexity of your document. If there are more than four XML depth levels in your HTML document then the SPACE character will be used as its delimiter (which is the default for levels 2 and greater). Specifying NEWLINE delimiters simply makes the resulting text a little more readable.
Try it for yourself.
In this example the input to xmlfy will come from a text file called file.txt and will look literally as follows:
Less-than: <<<<< Greater-than: >>>>> Quote: """"" Apostrophe: ''''' Broken-vertical-bar: ¦¦¦¦¦ Ampersand: &&&&&
The output using this text file:
% cat file.txt | xmlfy --noxml -X noescape brvbar Less-than: <<<<< Greater-than: >>>>> Quote: """"" Apostrophe: ''''' Broken-vertical-bar: ¦¦¦¦¦ Ampersand: &&&&&
In this example the /etc/passwd file will be converted to HTML using a DTD file called passwd.dtd and an XSLT stylesheet called passwd.xslt in conjuction with the xmlfy and xsltproc shell commands:
Create the following DTD file and save it as passwd.dtd
<!-- xmlfy-args: -F2 : -A0 timestamp --> <!ELEMENT passwordfile (user*)> <!ELEMENT user (name, pw, uid, gid, fullname?, home?, shell?)> <!ELEMENT name (#PCDATA)> <!ELEMENT pw (#PCDATA)> <!ELEMENT uid (#PCDATA)> <!ELEMENT gid (#PCDATA)> <!ELEMENT fullname (#PCDATA)> <!ELEMENT home (#PCDATA)> <!ELEMENT shell (#PCDATA)>
Create the following XSLT file and save it as passwd.xslt
<?xml version="1.0" encoding="UTF-8"?> <!-- Style sheet: /etc/passwd file processing Version: 1.0 Author: Arthur Gouros --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:decimal-format decimal-separator="." grouping-separator="," /> <xsl:template name="timestamp"> <xsl:value-of select="//passwordfile/@timestamp_date"/> </xsl:template> <xsl:template match="passwordfile"> <html> <head> <title>Report: /etc/passwd file</title> <style type="text/css"> body { margin-left: 10; margin-right: 10; font:normal 80% arial,helvetica,sanserif; background-color:#FFFFFF; color:#000000; } .a td { background: #efefef; } .b td { background: #fff; } th, td { text-align: left; vertical-align: top; } th { font-weight:bold; background: #ccc; color: black; } table, th, td { font-size:100%; border: none } table.log tr td, tr th { } h2 { font-weight:bold; font-size:120%; margin-top: 2; margin-bottom: 2; } h3 { font-size:100%; font-weight:bold; background: #525D76; color: white; text-decoration: none; padding: 5px; margin-right: 2px; margin-left: 2px; margin-bottom: 0; } </style> </head> <body> <a name="top"></a> <hr/> <!-- Header part --> <h2>Report: /etc/passwd file</h2> <p><small><i>Report created: <xsl:call-template name="timestamp"/></i></small></p> <!-- Summary part --> <h3>Summary</h3> <xsl:apply-templates select="." mode="summary"/> <!-- User part --> <h3>Users</h3> <xsl:apply-templates select="." mode="users"/> <!-- End-of-Report part --> <hr size="1" width="100%" align="left"/> <p><b>End of report.</b></p> <p><a href="#top"><small>Back to top</small></a></p> <hr/> </body> </html> </xsl:template> <xsl:template match="passwordfile" mode="summary"> <xsl:variable name="nusers" select="count(user)"/> <p>Sorted by User ID</p> <p>Number of users: <xsl:value-of select="$nusers"/></p> </xsl:template> <xsl:template match="passwordfile" mode="users"> <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%"> <tr> <th width="15%">Username</th> <th width="5%">Password</th> <th width="10%">User ID</th> <th width="10%">Group ID</th> <th>Full Name</th> <th width="25%">Home</th> <th width="10%">Shell</th> </tr> <xsl:for-each select="user"> <xsl:sort data-type="number" order="ascending" select="uid"/> <tr> <xsl:call-template name="alternated-row"/> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="pw"/></td> <td><xsl:value-of select="uid"/></td> <td><xsl:value-of select="gid"/></td> <td><xsl:value-of select="fullname"/></td> <td><xsl:value-of select="home"/></td> <td><xsl:value-of select="shell"/></td> </tr> </xsl:for-each> </table> </xsl:template> <xsl:template name="alternated-row"> <xsl:attribute name="class"> <xsl:if test="position() mod 2 = 1">a</xsl:if> <xsl:if test="position() mod 2 = 0">b</xsl:if> </xsl:attribute> </xsl:template> </xsl:stylesheet>
Run the following command to produce a HTML file from the /etc/passwd file:
% cat /etc/passwd | xmlfy -S passwd.dtd | xsltproc passwd.xslt - > passwd.html
Click the following link to see an example of the resulting file passwd.html.
In this example the input to xmlfy will come from a text file called numbers and will look as follows:
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9
Create the following DTD file and save to /usr/share/schemata/data/numbers.dtd
<!ELEMENT command (line_a) (line_b*)> <!ELEMENT line_a (b, c)> <!ELEMENT line_b (a, b, c)> <!ELEMENT line_b (d)> <!ELEMENT a (#PCDATA)> <!ELEMENT b (#PCDATA)> <!ELEMENT c (#PCDATA)> <!ELEMENT d (#PCDATA)>
The output using this custom DTD file:
% cat numbers | xmlfy -S /usr/share/schemata/data/numbers.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE command SYSTEM "/usr/share/schemata/data/numbers.dtd"> <command> <line_b> <d>1</d> </line_b> <line_a> <b>1</b> <c>2</c> </line_a> <line_b> <a>1</a> <b>2</b> <c>3</c> </line_b> </command>
ANALYSIS:
Create the following DTD file and save to /usr/share/schemata/data/numbers.dtd
<!ELEMENT command (line_a) (line_b?)> <!ELEMENT line_a (b, c)> <!ELEMENT line_b (a, b, c)> <!ELEMENT line_b (d)> <!ELEMENT a (#PCDATA)> <!ELEMENT b (#PCDATA)> <!ELEMENT c (#PCDATA)> <!ELEMENT d (#PCDATA)>
The output using this custom DTD file:
% cat numbers | xmlfy -S /usr/share/schemata/data/numbers.dtd -s <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE command SYSTEM "/usr/share/schemata/data/numbers.dtd"> <command> <line_b> <d>1</d> </line_b> <line_a> <b>1</b> <c>2</c> </line_a> </command> <command_summary> <version>1.0.0</version> <timestamp>Mon May 12 13:08:58 2008</timestamp> <args> <arg>xmlfy</arg> <arg>-S</arg> <arg>/usr/share/schemata/data/numbers.dtd</arg> <arg>-s</arg> </args> <separator> <record>NEWLINE</record> <field>WHITESPACE</field> </separator> <dtd> <default>false</default> <file>/usr/share/schemata/data/numbers.dtd</file> <parentname>command</parentname> <elements> <line_a> <match_control>MATCH_ONE</match_control> <instance1> <fields>2</fields> </instance1> </line_a> <line_b> <match_control>MATCH_NONE_OR_ONE</match_control> <instance1> <fields>3</fields> </instance1> <instance2> <fields>1</fields> </instance2> </line_b> </elements> <records> <elements> <line_a> <total>1</total> <instance1>1</instance1> </line_a> <line_b> <total>1</total> <instance1>0</instance1> <instance2>1</instance2> </line_b> </elements> <read>9</read> <matched>2</matched> <unmatched>7</unmatched> <ignoredblank>0</ignoredblank> <printed>2</printed> </records> </dtd> </command_summary>
ANALYSIS:
Create the following DTD file and save to /usr/share/schemata/data/numbers.dtd
<!ELEMENT command (line_a) (line_b+)> <!ELEMENT line_a (b, c)> <!ELEMENT line_b (a, b, c)> <!ELEMENT line_b (d*)> <!ELEMENT a (#PCDATA)> <!ELEMENT b (#PCDATA)> <!ELEMENT c (#PCDATA)> <!ELEMENT d (#PCDATA)>
The output using this custom DTD file:
% cat numbers | xmlfy -S /usr/share/schemata/data/numbers.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE command SYSTEM "/usr/share/schemata/data/numbers.dtd"> <command> <line_b> <d>1</d> </line_b> <line_a> <b>1</b> <c>2</c> </line_a> <line_b> <a>1</a> <b>2</b> <c>3</c> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> <d>5</d> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> <d>5</d> <d>6</d> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> <d>5</d> <d>6</d> <d>7</d> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> <d>5</d> <d>6</d> <d>7</d> <d>8</d> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> <d>5</d> <d>6</d> <d>7</d> <d>8</d> <d>9</d> </line_b> </command>
ANALYSIS:
Create the following DTD file and save to /usr/share/schemata/data/numbers.dtd
<!ELEMENT command (line_a) (line_b?) (line_b?) (line_b?) (line_b?)> <!ELEMENT line_a (b, c)> <!ELEMENT line_b (a, b, c)> <!ELEMENT line_b (d*)> <!ELEMENT a (#PCDATA)> <!ELEMENT b (#PCDATA)> <!ELEMENT c (#PCDATA)> <!ELEMENT d (#PCDATA)>
The output using this custom DTD file:
% cat numbers | xmlfy -S /usr/share/schemata/data/numbers.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE command SYSTEM "/usr/share/schemata/data/numbers.dtd"> <command> <line_b> <d>1</d> </line_b> <line_a> <b>1</b> <c>2</c> </line_a> <line_b> <a>1</a> <b>2</b> <c>3</c> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> </line_b> <line_b> <d>1</d> <d>2</d> <d>3</d> <d>4</d> <d>5</d> </line_b> </command>
ANALYSIS:
In this example the input to xmlfy will come from the Linux RedHat 4 ping -c 4 localhost command and will look as follows:
PING rh4as.a.com (127.0.0.1) 56(84) bytes of data. 64 bytes from rh4as.a.com (127.0.0.1): icmp_seq=0 ttl=64 time=0.151 ms 64 bytes from rh4as.a.com (127.0.0.1): icmp_seq=1 ttl=64 time=0.039 ms 64 bytes from rh4as.a.com (127.0.0.1): icmp_seq=2 ttl=64 time=0.044 ms 64 bytes from rh4as.a.com (127.0.0.1): icmp_seq=3 ttl=64 time=0.037 ms --- rh4as.a.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2999ms rtt min/avg/max/mdev = 0.037/0.067/0.151/0.049 ms, pipe 2
Create the following DTD file and save to /usr/share/schemata/linux/ping.dtd
<!ELEMENT netstat (info), (ping+), (summary_title), (summary_packets), (summary_times)> <!ELEMENT info (p, host, ip, size, size_unit, p*)> <!ELEMENT ping (size, size_unit, p, host, ip, seq, ttl, time, time_unit)> <!ELEMENT summary_title (p, host, p+)> <!ELEMENT summary_packets (transmitted, p, p, received, p, loss, p+, time)> <!ELEMENT summary_times (type, titles, p, values, p+)> <!ELEMENT p (#PCDATA)> <!ELEMENT host (#PCDATA)> <!ELEMENT ip (#PCDATA)> <!ELEMENT size (#PCDATA)> <!ELEMENT size_unit (#PCDATA)> <!ELEMENT seq (#PCDATA)> <!ELEMENT ttl (#PCDATA)> <!ELEMENT time (#PCDATA)> <!ELEMENT time_unit (#PCDATA)> <!ELEMENT transmitted (#PCDATA)> <!ELEMENT received (#PCDATA)> <!ELEMENT loss (#PCDATA)> <!ELEMENT type (#PCDATA)> <!ELEMENT titles (#PCDATA)> <!ELEMENT values (#PCDATA)>
The output using this custom DTD file:
% ping -c 4 localhost | xmlfy -S /usr/share/schemata/linux/ping.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE netstat SYSTEM "/usr/share/schemata/linux/ping.dtd"> <netstat> <info> <p>PING</p> <host>rh4as.a.com</host> <ip>(127.0.0.1)</ip> <size>56(84)</size> <size_unit>bytes</size_unit> <p>of</p> <p>data.</p> </info> <ping> <size>64</size> <size_unit>bytes</size_unit> <p>from</p> <host>rh4as.a.com</host> <ip>(127.0.0.1):</ip> <seq>icmp_seq=0</seq> <ttl>ttl=64</ttl> <time>time=0.151</time> <time_unit>ms</time_unit> </ping> <ping> <size>64</size> <size_unit>bytes</size_unit> <p>from</p> <host>rh4as.a.com</host> <ip>(127.0.0.1):</ip> <seq>icmp_seq=1</seq> <ttl>ttl=64</ttl> <time>time=0.039</time> <time_unit>ms</time_unit> </ping> <ping> <size>64</size> <size_unit>bytes</size_unit> <p>from</p> <host>rh4as.a.com</host> <ip>(127.0.0.1):</ip> <seq>icmp_seq=2</seq> <ttl>ttl=64</ttl> <time>time=0.044</time> <time_unit>ms</time_unit> </ping> <ping> <size>64</size> <size_unit>bytes</size_unit> <p>from</p> <host>rh4as.a.com</host> <ip>(127.0.0.1):</ip> <seq>icmp_seq=3</seq> <ttl>ttl=64</ttl> <time>time=0.037</time> <time_unit>ms</time_unit> </ping> <summary_title> <p>---</p> <host>rh4as.a.com</host> <p>ping</p> <p>statistics</p> <p>---</p> </summary_title> <summary_packets> <transmitted>4</transmitted> <p>packets</p> <p>transmitted,</p> <received>4</received> <p>received,</p> <loss>0%</loss> <p>packet</p> <p>loss,</p> <p>time</p> <time>2999ms</time> </summary_packets> <summary_times> <type>rtt</type> <titles>min/avg/max/mdev</titles> <p>=</p> <values>0.037/0.067/0.151/0.049</values> <p>ms,</p> <p>pipe</p> <p>2</p> </summary_times> </netstat>
If the pinged host does not exist the following output is produced:
PING 169.254.1.1 (169.254.1.1) 56(84) bytes of data. --- 169.254.1.1 ping statistics --- 4 packets transmitted, 0 received, 100% packet loss, time 3000ms
The output using the same DTD file:
% ping -c 4 169.254.1.1 | xmlfy -S /usr/share/schemata/linux/ping.dtd <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE netstat SYSTEM "/usr/share/schemata/linux/ping.dtd"> <netstat> <info> <p>PING</p> <host>169.254.1.1</host> <ip>(169.254.1.1)</ip> <size>56(84)</size> <size_unit>bytes</size_unit> <p>of</p> <p>data.</p> </info> <summary_title> <p>---</p> <host>169.254.1.1</host> <p>ping</p> <p>statistics</p> <p>---</p> </summary_title> <summary_packets> <transmitted>4</transmitted> <p>packets</p> <p>transmitted,</p> <received>0</received> <p>received,</p> <loss>100%</loss> <p>packet</p> <p>loss,</p> <p>time</p> <time>3000ms</time> </summary_packets> </netstat>
In this example the input to xmlfy will come from the Linux RedHat 4 netstat -s command and will look as follows:
Ip: 1623 total packets received 0 forwarded 0 incoming packets discarded 1623 incoming packets delivered 1623 requests sent out Icmp: 0 ICMP messages received 0 input ICMP message failed. ICMP input histogram: 0 ICMP messages sent 0 ICMP messages failed ICMP output histogram: Tcp: 2 active connections openings 2 passive connection openings 0 failed connection attempts 0 connection resets received 0 connections established 1615 segments received 1615 segments send out 0 segments retransmited 0 bad segments received. 0 resets sent Udp: 8 packets received 0 packets to unknown port received. 0 packet receive errors 8 packets sent TcpExt: ArpFilter: 0 2 TCP sockets finished time wait in fast timer 331 delayed acks sent 4 packets directly queued to recvmsg prequeue. 239 packets directly received from backlog 54 packets directly received from prequeue 292 packets header predicted 3 packets header predicted and directly queued to user TCPPureAcks: 38 TCPHPAcks: 618 TCPRenoRecovery: 0 TCPSackRecovery: 0 TCPSACKReneging: 0 TCPFACKReorder: 0 TCPSACKReorder: 0 TCPRenoReorder: 0 TCPTSReorder: 0 TCPFullUndo: 0 TCPPartialUndo: 0 TCPDSACKUndo: 0 TCPLossUndo: 0 TCPLoss: 0 TCPLostRetransmit: 0 TCPRenoFailures: 0 TCPSackFailures: 0 TCPLossFailures: 0 TCPFastRetrans: 0 TCPForwardRetrans: 0 TCPSlowStartRetrans: 0 TCPTimeouts: 0 TCPRenoRecoveryFail: 0 TCPSackRecoveryFail: 0 TCPSchedulerFailed: 0 TCPRcvCollapsed: 0 TCPDSACKOldSent: 0 TCPDSACKOfoSent: 0 TCPDSACKRecv: 0 TCPDSACKOfoRecv: 0 TCPAbortOnSyn: 0 TCPAbortOnData: 0 TCPAbortOnClose: 0 TCPAbortOnMemory: 0 TCPAbortOnTimeout: 0 TCPAbortOnLinger: 0 TCPAbortFailed: 0 TCPMemoryPressures: 0
It is obvious that the structure of the data returned from the netstat -s command is complex and does not follow consistent rules (e.g. field descriptors alternate with field values, some fields are delimited by colons others are not, and title headings are ambiguous in that they are represented by the lack of leading white space).
This structure of data is a little too complex for xmlfy to handle in its current form, but with some experimentation we can break it down into a usable XML format.
Use the : (colon) character as the field separator. Trim fields of whitespace.
% netstat -s | xmlfy -F : -t <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line> <field>Ip</field> <field></field> </line> <line> <field>1623 total packets received</field> </line> <line> <field>0 forwarded</field> </line> <line> <field>0 incoming packets discarded</field> </line> <line> <field>1623 incoming packets delivered</field> </line> <line> <field>1623 requests sent out</field> </line> <line> <field>Icmp</field> <field></field> </line> <line> <field>0 ICMP messages received</field> </line> <line> <field>0 input ICMP message failed.</field> </line> <line> <field>ICMP input histogram</field> <field></field> </line> <line> <field>0 ICMP messages sent</field> </line> <line> <field>0 ICMP messages failed</field> </line> <line> <field>ICMP output histogram</field> <field></field> </line> <line> <field>Tcp</field> <field></field> </line> <line> <field>2 active connections openings</field> </line> <line> <field>2 passive connection openings</field> </line> <line> <field>0 failed connection attempts</field> </line> <line> <field>0 connection resets received</field> </line> <line> <field>0 connections established</field> </line> <line> <field>1615 segments received</field> </line> <line> <field>1615 segments send out</field> </line> <line> <field>0 segments retransmited</field> </line> <line> <field>0 bad segments received.</field> </line> <line> <field>0 resets sent</field> </line> <line> <field>Udp</field> <field></field> </line> <line> <field>8 packets received</field> </line> <line> <field>0 packets to unknown port received.</field> </line> <line> <field>0 packet receive errors</field> </line> <line> <field>8 packets sent</field> </line> <line> <field>TcpExt</field> <field></field> </line> <line> <field>ArpFilter</field> <field>0</field> </line> <line> <field>2 TCP sockets finished time wait in fast timer</field> </line> <line> <field>331 delayed acks sent</field> </line> <line> <field>4 packets directly queued to recvmsg prequeue.</field> </line> <line> <field>239 packets directly received from backlog</field> </line> <line> <field>54 packets directly received from prequeue</field> </line> <line> <field>292 packets header predicted</field> </line> <line> <field>3 packets header predicted and directly queued to user</field> </line> <line> <field>TCPPureAcks</field> <field>38</field> </line> <line> <field>TCPHPAcks</field> <field>618</field> </line> <line> <field>TCPRenoRecovery</field> <field>0</field> </line> <line> <field>TCPSackRecovery</field> <field>0</field> </line> <line> <field>TCPSACKReneging</field> <field>0</field> </line> <line> <field>TCPFACKReorder</field> <field>0</field> </line> <line> <field>TCPSACKReorder</field> <field>0</field> </line> <line> <field>TCPRenoReorder</field> <field>0</field> </line> <line> <field>TCPTSReorder</field> <field>0</field> </line> <line> <field>TCPFullUndo</field> <field>0</field> </line> <line> <field>TCPPartialUndo</field> <field>0</field> </line> <line> <field>TCPDSACKUndo</field> <field>0</field> </line> <line> <field>TCPLossUndo</field> <field>0</field> </line> <line> <field>TCPLoss</field> <field>0</field> </line> <line> <field>TCPLostRetransmit</field> <field>0</field> </line> <line> <field>TCPRenoFailures</field> <field>0</field> </line> <line> <field>TCPSackFailures</field> <field>0</field> </line> <line> <field>TCPLossFailures</field> <field>0</field> </line> <line> <field>TCPFastRetrans</field> <field>0</field> </line> <line> <field>TCPForwardRetrans</field> <field>0</field> </line> <line> <field>TCPSlowStartRetrans</field> <field>0</field> </line> <line> <field>TCPTimeouts</field> <field>0</field> </line> <line> <field>TCPRenoRecoveryFail</field> <field>0</field> </line> <line> <field>TCPSackRecoveryFail</field> <field>0</field> </line> <line> <field>TCPSchedulerFailed</field> <field>0</field> </line> <line> <field>TCPRcvCollapsed</field> <field>0</field> </line> <line> <field>TCPDSACKOldSent</field> <field>0</field> </line> <line> <field>TCPDSACKOfoSent</field> <field>0</field> </line> <line> <field>TCPDSACKRecv</field> <field>0</field> </line> <line> <field>TCPDSACKOfoRecv</field> <field>0</field> </line> <line> <field>TCPAbortOnSyn</field> <field>0</field> </line> <line> <field>TCPAbortOnData</field> <field>0</field> </line> <line> <field>TCPAbortOnClose</field> <field>0</field> </line> <line> <field>TCPAbortOnMemory</field> <field>0</field> </line> <line> <field>TCPAbortOnTimeout</field> <field>0</field> </line> <line> <field>TCPAbortOnLinger</field> <field>0</field> </line> <line> <field>TCPAbortFailed</field> <field>0</field> </line> <line> <field>TCPMemoryPressures</field> <field>0</field> </line> </xmlfy>
Use the ^ character as the record separator of which none are present making the entire output one record. Use '\n' (newline) character as the field separator. Trim fields of whitespace.
% netstat -s | xmlfy -R '^' -F '\n' -t <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line> <field>Ip:</field> <field>1623 total packets received</field> <field>0 forwarded</field> <field>0 incoming packets discarded</field> <field>1623 incoming packets delivered</field> <field>1623 requests sent out</field> <field>Icmp:</field> <field>0 ICMP messages received</field> <field>0 input ICMP message failed.</field> <field>ICMP input histogram:</field> <field>0 ICMP messages sent</field> <field>0 ICMP messages failed</field> <field>ICMP output histogram:</field> <field>Tcp:</field> <field>2 active connections openings</field> <field>2 passive connection openings</field> <field>0 failed connection attempts</field> <field>0 connection resets received</field> <field>0 connections established</field> <field>1615 segments received</field> <field>1615 segments send out</field> <field>0 segments retransmited</field> <field>0 bad segments received.</field> <field>0 resets sent</field> <field>Udp:</field> <field>8 packets received</field> <field>0 packets to unknown port received.</field> <field>0 packet receive errors</field> <field>8 packets sent</field> <field>TcpExt:</field> <field>ArpFilter: 0</field> <field>2 TCP sockets finished time wait in fast timer</field> <field>331 delayed acks sent</field> <field>4 packets directly queued to recvmsg prequeue.</field> <field>239 packets directly received from backlog</field> <field>54 packets directly received from prequeue</field> <field>292 packets header predicted</field> <field>3 packets header predicted and directly queued to user</field> <field>TCPPureAcks: 38</field> <field>TCPHPAcks: 618</field> <field>TCPRenoRecovery: 0</field> <field>TCPSackRecovery: 0</field> <field>TCPSACKReneging: 0</field> <field>TCPFACKReorder: 0</field> <field>TCPSACKReorder: 0</field> <field>TCPRenoReorder: 0</field> <field>TCPTSReorder: 0</field> <field>TCPFullUndo: 0</field> <field>TCPPartialUndo: 0</field> <field>TCPDSACKUndo: 0</field> <field>TCPLossUndo: 0</field> <field>TCPLoss: 0</field> <field>TCPLostRetransmit: 0</field> <field>TCPRenoFailures: 0</field> <field>TCPSackFailures: 0</field> <field>TCPLossFailures: 0</field> <field>TCPFastRetrans: 0</field> <field>TCPForwardRetrans: 0</field> <field>TCPSlowStartRetrans: 0</field> <field>TCPTimeouts: 0</field> <field>TCPRenoRecoveryFail: 0</field> <field>TCPSackRecoveryFail: 0</field> <field>TCPSchedulerFailed: 0</field> <field>TCPRcvCollapsed: 0</field> <field>TCPDSACKOldSent: 0</field> <field>TCPDSACKOfoSent: 0</field> <field>TCPDSACKRecv: 0</field> <field>TCPDSACKOfoRecv: 0</field> <field>TCPAbortOnSyn: 0</field> <field>TCPAbortOnData: 0</field> <field>TCPAbortOnClose: 0</field> <field>TCPAbortOnMemory: 0</field> <field>TCPAbortOnTimeout: 0</field> <field>TCPAbortOnLinger: 0</field> <field>TCPAbortFailed: 0</field> <field>TCPMemoryPressures: 0</field> <field></field> </line> </xmlfy>
Create the following DTD file and save to /usr/share/schemata/linux/netstat.dtd
<!ELEMENT netstat (category*), (data+)> <!ELEMENT category (title)> <!ELEMENT data (param+)> <!ELEMENT title (#PCDATA)> <!ELEMENT param (#PCDATA)>
The output using this custom DTD file:
% netstat -s | xmlfy -S /usr/share/schemata/linux/netstat.dtd -L -t <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE netstat SYSTEM "/usr/share/schemata/linux/netstat.dtd"> <netstat> <category> <linenumber>1</linenumber> <title>Ip:</title> </category> <data> <linenumber>1</linenumber> <param>1623</param> <param>total</param> <param>packets</param> <param>received</param> </data> <data> <linenumber>2</linenumber> <param>0</param> <param>forwarded</param> </data> <data> <linenumber>3</linenumber> <param>0</param> <param>incoming</param> <param>packets</param> <param>discarded</param> </data> <data> <linenumber>4</linenumber> <param>1623</param> <param>incoming</param> <param>packets</param> <param>delivered</param> </data> <data> <linenumber>5</linenumber> <param>1623</param> <param>requests</param> <param>sent</param> <param>out</param> </data> <category> <linenumber>2</linenumber> <title>Icmp:</title> </category> <data> <linenumber>6</linenumber> <param>0</param> <param>ICMP</param> <param>messages</param> <param>received</param> </data> <data> <linenumber>7</linenumber> <param>0</param> <param>input</param> <param>ICMP</param> <param>message</param> <param>failed.</param> </data> <data> <linenumber>8</linenumber> <param>ICMP</param> <param>input</param> <param>histogram:</param> </data> <data> <linenumber>9</linenumber> <param>0</param> <param>ICMP</param> <param>messages</param> <param>sent</param> </data> <data> <linenumber>10</linenumber> <param>0</param> <param>ICMP</param> <param>messages</param> <param>failed</param> </data> <data> <linenumber>11</linenumber> <param>ICMP</param> <param>output</param> <param>histogram:</param> </data> <category> <linenumber>3</linenumber> <title>Tcp:</title> </category> <data> <linenumber>12</linenumber> <param>2</param> <param>active</param> <param>connections</param> <param>openings</param> </data> <data> <linenumber>13</linenumber> <param>2</param> <param>passive</param> <param>connection</param> <param>openings</param> </data> <data> <linenumber>14</linenumber> <param>0</param> <param>failed</param> <param>connection</param> <param>attempts</param> </data> <data> <linenumber>15</linenumber> <param>0</param> <param>connection</param> <param>resets</param> <param>received</param> </data> <data> <linenumber>16</linenumber> <param>0</param> <param>connections</param> <param>established</param> </data> <data> <linenumber>17</linenumber> <param>1615</param> <param>segments</param> <param>received</param> </data> <data> <linenumber>18</linenumber> <param>1615</param> <param>segments</param> <param>send</param> <param>out</param> </data> <data> <linenumber>19</linenumber> <param>0</param> <param>segments</param> <param>retransmited</param> </data> <data> <linenumber>20</linenumber> <param>0</param> <param>bad</param> <param>segments</param> <param>received.</param> </data> <data> <linenumber>21</linenumber> <param>0</param> <param>resets</param> <param>sent</param> </data> <category> <linenumber>4</linenumber> <title>Udp:</title> </category> <data> <linenumber>22</linenumber> <param>8</param> <param>packets</param> <param>received</param> </data> <data> <linenumber>23</linenumber> <param>0</param> <param>packets</param> <param>to</param> <param>unknown</param> <param>port</param> <param>received.</param> </data> <data> <linenumber>24</linenumber> <param>0</param> <param>packet</param> <param>receive</param> <param>errors</param> </data> <data> <linenumber>25</linenumber> <param>8</param> <param>packets</param> <param>sent</param> </data> <category> <linenumber>5</linenumber> <title>TcpExt:</title> </category> <data> <linenumber>26</linenumber> <param>ArpFilter:</param> <param>0</param> </data> <data> <linenumber>27</linenumber> <param>2</param> <param>TCP</param> <param>sockets</param> <param>finished</param> <param>time</param> <param>wait</param> <param>in</param> <param>fast</param> <param>timer</param> </data> <data> <linenumber>28</linenumber> <param>331</param> <param>delayed</param> <param>acks</param> <param>sent</param> </data> <data> <linenumber>29</linenumber> <param>4</param> <param>packets</param> <param>directly</param> <param>queued</param> <param>to</param> <param>recvmsg</param> <param>prequeue.</param> </data> <data> <linenumber>30</linenumber> <param>239</param> <param>packets</param> <param>directly</param> <param>received</param> <param>from</param> <param>backlog</param> </data> <data> <linenumber>31</linenumber> <param>54</param> <param>packets</param> <param>directly</param> <param>received</param> <param>from</param> <param>prequeue</param> </data> <data> <linenumber>32</linenumber> <param>292</param> <param>packets</param> <param>header</param> <param>predicted</param> </data> <data> <linenumber>33</linenumber> <param>3</param> <param>packets</param> <param>header</param> <param>predicted</param> <param>and</param> <param>directly</param> <param>queued</param> <param>to</param> <param>user</param> </data> <data> <linenumber>34</linenumber> <param>TCPPureAcks:</param> <param>38</param> </data> <data> <linenumber>35</linenumber> <param>TCPHPAcks:</param> <param>618</param> </data> <data> <linenumber>36</linenumber> <param>TCPRenoRecovery:</param> <param>0</param> </data> <data> <linenumber>37</linenumber> <param>TCPSackRecovery:</param> <param>0</param> </data> <data> <linenumber>38</linenumber> <param>TCPSACKReneging:</param> <param>0</param> </data> <data> <linenumber>39</linenumber> <param>TCPFACKReorder:</param> <param>0</param> </data> <data> <linenumber>40</linenumber> <param>TCPSACKReorder:</param> <param>0</param> </data> <data> <linenumber>41</linenumber> <param>TCPRenoReorder:</param> <param>0</param> </data> <data> <linenumber>42</linenumber> <param>TCPTSReorder:</param> <param>0</param> </data> <data> <linenumber>43</linenumber> <param>TCPFullUndo:</param> <param>0</param> </data> <data> <linenumber>44</linenumber> <param>TCPPartialUndo:</param> <param>0</param> </data> <data> <linenumber>45</linenumber> <param>TCPDSACKUndo:</param> <param>0</param> </data> <data> <linenumber>46</linenumber> <param>TCPLossUndo:</param> <param>0</param> </data> <data> <linenumber>47</linenumber> <param>TCPLoss:</param> <param>0</param> </data> <data> <linenumber>48</linenumber> <param>TCPLostRetransmit:</param> <param>0</param> </data> <data> <linenumber>49</linenumber> <param>TCPRenoFailures:</param> <param>0</param> </data> <data> <linenumber>50</linenumber> <param>TCPSackFailures:</param> <param>0</param> </data> <data> <linenumber>51</linenumber> <param>TCPLossFailures:</param> <param>0</param> </data> <data> <linenumber>52</linenumber> <param>TCPFastRetrans:</param> <param>0</param> </data> <data> <linenumber>53</linenumber> <param>TCPForwardRetrans:</param> <param>0</param> </data> <data> <linenumber>54</linenumber> <param>TCPSlowStartRetrans:</param> <param>0</param> </data> <data> <linenumber>55</linenumber> <param>TCPTimeouts:</param> <param>0</param> </data> <data> <linenumber>56</linenumber> <param>TCPRenoRecoveryFail:</param> <param>0</param> </data> <data> <linenumber>57</linenumber> <param>TCPSackRecoveryFail:</param> <param>0</param> </data> <data> <linenumber>58</linenumber> <param>TCPSchedulerFailed:</param> <param>0</param> </data> <data> <linenumber>59</linenumber> <param>TCPRcvCollapsed:</param> <param>0</param> </data> <data> <linenumber>60</linenumber> <param>TCPDSACKOldSent:</param> <param>0</param> </data> <data> <linenumber>61</linenumber> <param>TCPDSACKOfoSent:</param> <param>0</param> </data> <data> <linenumber>62</linenumber> <param>TCPDSACKRecv:</param> <param>0</param> </data> <data> <linenumber>63</linenumber> <param>TCPDSACKOfoRecv:</param> <param>0</param> </data> <data> <linenumber>64</linenumber> <param>TCPAbortOnSyn:</param> <param>0</param> </data> <data> <linenumber>65</linenumber> <param>TCPAbortOnData:</param> <param>0</param> </data> <data> <linenumber>66</linenumber> <param>TCPAbortOnClose:</param> <param>0</param> </data> <data> <linenumber>67</linenumber> <param>TCPAbortOnMemory:</param> <param>0</param> </data> <data> <linenumber>68</linenumber> <param>TCPAbortOnTimeout:</param> <param>0</param> </data> <data> <linenumber>69</linenumber> <param>TCPAbortOnLinger:</param> <param>0</param> </data> <data> <linenumber>70</linenumber> <param>TCPAbortFailed:</param> <param>0</param> </data> <data> <linenumber>71</linenumber> <param>TCPMemoryPressures:</param> <param>0</param> </data> </netstat>
Use the ^ character as both the record separator and the field separator of which none are present making the entire output one field. Trim fields of whitespace.
% netstat -s | xmlfy -R '^' -F '^' -t <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xmlfy SYSTEM "xmlfy.dtd"> <xmlfy> <line> <field>Ip: 1623 total packets received 0 forwarded 0 incoming packets discarded 1623 incoming packets delivered 1623 requests sent out Icmp: 0 ICMP messages received 0 input ICMP message failed. ICMP input histogram: 0 ICMP messages sent 0 ICMP messages failed ICMP output histogram: Tcp: 2 active connections openings 2 passive connection openings 0 failed connection attempts 0 connection resets received 0 connections established 1615 segments received 1615 segments send out 0 segments retransmited 0 bad segments received. 0 resets sent Udp: 8 packets received 0 packets to unknown port received. 0 packet receive errors 8 packets sent TcpExt: ArpFilter: 0 2 TCP sockets finished time wait in fast timer 331 delayed acks sent 4 packets directly queued to recvmsg prequeue. 239 packets directly received from backlog 54 packets directly received from prequeue 292 packets header predicted 3 packets header predicted and directly queued to user TCPPureAcks: 38 TCPHPAcks: 618 TCPRenoRecovery: 0 TCPSackRecovery: 0 TCPSACKReneging: 0 TCPFACKReorder: 0 TCPSACKReorder: 0 TCPRenoReorder: 0 TCPTSReorder: 0 TCPFullUndo: 0 TCPPartialUndo: 0 TCPDSACKUndo: 0 TCPLossUndo: 0 TCPLoss: 0 TCPLostRetransmit: 0 TCPRenoFailures: 0 TCPSackFailures: 0 TCPLossFailures: 0 TCPFastRetrans: 0 TCPForwardRetrans: 0 TCPSlowStartRetrans: 0 TCPTimeouts: 0 TCPRenoRecoveryFail: 0 TCPSackRecoveryFail: 0 TCPSchedulerFailed: 0 TCPRcvCollapsed: 0 TCPDSACKOldSent: 0 TCPDSACKOfoSent: 0 TCPDSACKRecv: 0 TCPDSACKOfoRecv: 0 TCPAbortOnSyn: 0 TCPAbortOnData: 0 TCPAbortOnClose: 0 TCPAbortOnMemory: 0 TCPAbortOnTimeout: 0 TCPAbortOnLinger: 0 TCPAbortFailed: 0 TCPMemoryPressures: 0</field> </line> </xmlfy>
Use the netstat titles as the record delimiters, new-line as the field delimiter, and colon as the level 3 delimiter. Trim the fields and modify the default element tags.
% netstat -s | xmlfy -F1 "Ip:" -F1 "Icmp:" -F1 "Tcp:" -F1 "Udp:" -F1 "TcpExt:" -F2 "\n" -F3 ":" -t -A1 number -T0 name netstat -T1 name category -T3 level <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE netstat SYSTEM "xmlfy.dtd"> <netstat> <category number="1"> <field></field> <field>1623 total packets received</field> <field>0 forwarded</field> <field>0 incoming packets discarded</field> <field>1623 incoming packets delivered</field> <field>1623 requests sent out</field> <field></field> </category> <category number="2"> <field></field> <field>0 ICMP messages received</field> <field>0 input ICMP message failed.</field> <field> <L3field>ICMP input histogram</L3field> <L3field></L3field> </field> <field>0 ICMP messages sent</field> <field>0 ICMP messages failed</field> <field> <L3field>ICMP output histogram</L3field> <L3field></L3field> </field> <field></field> </category> <category number="3"> <field></field> <field>2 active connections openings</field> <field>2 passive connection openings</field> <field>0 failed connection attempts</field> <field>0 connection resets received</field> <field>0 connections established</field> <field>1615 segments received</field> <field>1615 segments send out</field> <field>0 segments retransmited</field> <field>0 bad segments received.</field> <field>0 resets sent</field> <field></field> </category> <category number="4"> <field></field> <field>8 packets received</field> <field>0 packets to unknown port received.</field> <field>0 packet receive errors</field> <field>8 packets sent</field> <field></field> </category> <category number="5"> <field></field> <field> <L3field>ArpFilter</L3field> <L3field>0</L3field> </field> <field>2 TCP sockets finished time wait in fast timer</field> <field>331 delayed acks sent</field> <field>4 packets directly queued to recvmsg prequeue.</field> <field>239 packets directly received from backlog</field> <field>54 packets directly received from prequeue</field> <field>292 packets header predicted</field> <field>3 packets header predicted and directly queued to user</field> <field> <L3field>TCPPureAcks</L3field> <L3field>38</L3field> </field> <field> <L3field>TCPHPAcks</L3field> <L3field>618</L3field> </field> <field> <L3field>TCPRenoRecovery</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSackRecovery</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSACKReneging</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPFACKReorder</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSACKReorder</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPRenoReorder</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPTSReorder</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPFullUndo</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPPartialUndo</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPDSACKUndo</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPLossUndo</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPLoss</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPLostRetransmit</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPRenoFailures</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSackFailures</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPLossFailures</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPFastRetrans</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPForwardRetrans</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSlowStartRetrans</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPTimeouts</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPRenoRecoveryFail</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSackRecoveryFail</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPSchedulerFailed</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPRcvCollapsed</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPDSACKOldSent</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPDSACKOfoSent</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPDSACKRecv</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPDSACKOfoRecv</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortOnSyn</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortOnData</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortOnClose</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortOnMemory</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortOnTimeout</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortOnLinger</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPAbortFailed</L3field> <L3field>0</L3field> </field> <field> <L3field>TCPMemoryPressures</L3field> <L3field>0</L3field> </field> <field></field> </category> </netstat>