Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

HALP PLIZ!!!

Name: A fag 2011-05-31 18:03

Dear faggots:

First, some background
I just have XML::Parser and XML::Writer available, nothing else.
Language is perl 5.8.8

I have this XML. I have succesfully read this in memory, modified it, and now i have to write it back.

The XML in need to write:

<userdef depends="" src="CustomDef">
    <port>
        <Group NTYPE="ROOT" NAME="DPV" TYPE="TOP" GID="ID_T1234">
            <Group NAME="TEST_DPV" TYPE="BOOK" GID="ID_T9999">
                <Position RANKING="0" POS="100" SEC_ID="BD-TEST-1"/>
                <Position RANKING="0" POS="200" SEC_ID="BD-TEST-2"/>
            </Group>
        </Group>
    </port>
</userdef>


The data structure:

$VAR1 = [
          'userdef',
          [
            {
              'src' => 'CustomDef',
              'depends' => ''
            },
            0,
            '
    ',
            'port',
            [
              {},
              0,
              '
        ',
              'Group',
              [
                {
                  'NAME' => 'DPV',
                  'GID' => 'ID_T1234',
                  'TYPE' => 'TOP',
                  'NTYPE' => 'ROOT'
                },
                0,
                '
            ',
                'Group',
                [
                  {
                    'NAME' => 'TEST_DPV',
                    'GID' => 'ID_T9999',
                    'TYPE' => 'BOOK'
                  },
                  0,
                  '
                ',
                  'Position',
                  [
                    {
                      'RANKING' => '0',
                      'SEC_ID' => 'BD-TEST-1',
                      'POS' => '100'
                    }
                  ],
                  0,
                  '
                ',
                  'Position',
                  [
                    {
                      'RANKING' => '0',
                      'SEC_ID' => 'BD-TEST-2',
                      'POS' => '200'
                    }
                  ],
                  0,
                  '
            '
                ],
                0,
                '
        '
              ],
              0,
              '
    '
            ],
            0,
            '
'
          ]
        ];


I can't make a recursive algorithm to write this?

Care to help? If you do, i will donate 10 bucks to the FSF.

Name: Anonymous 2011-05-31 18:05

>>1
You have XML::Writer, can't you use it to write it back?

i will donate 10 bucks to the FSF.
No, please don't.

Name: Anonymous 2011-05-31 18:09

I just can't pass the structure to XML::Writer. XML::Writer is helpful, but i still have to recurse the structure. I'm currently failing at this.

Name: Anonymous 2011-05-31 18:13

So like, my girlfriend wants to shove her dildo up my ass.

Name: Anonymous 2011-05-31 18:17

>>3
You can't just

$tag = shift @xml;
%attribs = shift @xml;
$res = '<$tag ' + stringize_attribs(%attribs) /* for each $key,$value: '$key="$value"' */;
if (not_empty(@xml)) return $res + '/>';
else map(this_function,@xml[2:])


Not valid Perl code (I think), but that's the point.

Name: Anonymous 2011-05-31 18:19

>>5
2/10 for baiting to retard.

Name: Anonymous 2011-05-31 18:20

*baiting the retard*

Name: Anonymous 2011-05-31 18:22

>>5
DON'T HELP HIM!!

Name: Anonymous 2011-05-31 18:23

I have no fucking idea why you'd need an entire bloated library just to do what a few well-formatted print statements would do.

Name: Anonymous 2011-05-31 18:27

>>9
The XML can have other data i should not touch (example, other <port></port>'s). So i need to pass the XML to memory, change only a few parts and then write it all back.

Name: Anonymous 2011-05-31 18:50

The jews are after me.

Name: Anonymous 2011-05-31 20:40

#!/usr/bin/perl
use warnings;
use strict;

use XML::Writer;

sub wang {
    my ($xml, $p) = @_;
    while (@$p) {
        my ($tag, $contents, @rest) = @$p;
        if ($tag eq '0') {
            # no.
        } else {
            my ($attr, @children) = @$contents;
            $xml->startTag($tag, %$attr);
            wang($xml, \@children);
            $xml->endTag($tag);
        }
        $p = \@rest;
    }
}

my $data = [
          'userdef',
          [
            {
              'src' => 'CustomDef',
              'depends' => ''
            },
            0,
            '
    ',
            'port',
            [
              {},
              0,
              '
        ',
              'Group',
              [
                {
                  'NAME' => 'DPV',
                  'GID' => 'ID_T1234',
                  'TYPE' => 'TOP',
                  'NTYPE' => 'ROOT'
                },
                0,
                '
            ',
                'Group',
                [
                  {
                    'NAME' => 'TEST_DPV',
                    'GIRTH' => 'ID_T9999',
                    'TYPE' => 'BOOK'
                  },
                  0,
                  '
                ',
                  'Position',
                  [
                    {
                      'RANKING' => '0',
                      'SEC_ID' => 'BD-TEST-1',
                      'POS' => '100'
                    }
                  ],
                  0,
                  '
                ',
                  'Position',
                  [
                    {
                      'RANKING' => '0',
                      'SEC_ID' => 'BD-TEST-2',
                      'POS' => '200'
                    }
                  ],
                  0,
                  '
            '
                ],
                0,
                '
        '
              ],
              0,
              '
    '
            ],
            0,
            '
'
          ]
        ];

my $xml = XML::Writer->new(
    OUTPUT => \*STDOUT,
    CHECK_PRINT => 1,
    DATA_MODE => 1,
    DATA_INDENT => ' ' x 4,
);

$xml->comment('All data is (C) 2011 Anonymous.');
$xml->comment('*holds up spork*');
wang($xml, $data);
$xml->end;

Name: Anonymous 2011-05-31 20:54

>>11
Are the jews still after you?

Name: Anonymous 2011-05-31 21:00

>>13
Not anymore.

Name: Grateful fag 2011-06-01 11:00

>>12

Thanks!

Instead of the FSF, I'm donating the 10 bucks to the Perl Foundation. It seems more appropiate.

Name: Anonymous 2011-06-01 11:27

>>15
How about fuck off now?

Name: Anonymous 2011-06-01 11:48

>>15
You're too stupid to use a computer. Do society a favor and disconnect your computer from the internet. After that, consider ritual suicide.

Name: Anonymous 2011-06-01 18:09

>>15
i demand you report that transaction as fraudulent and instead redirect the funds to the python software foundation

Name: Anonymous 2011-06-01 18:12

>>18
Nope.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List