cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2007
Views
0
Helpful
1
Replies

CiscoWorks DEE not exporting well-formed XML

mfreeman451
Level 1
Level 1

Has anyone else expierenced CW2000 generating bad XML? It's firing out invalid XML tags for the VLAN stuff right now:

ERROR in '':

not well-formed (invalid token) at line 5312, column 9, byte 223636:

</Spanning-tree>

<Vlan>

<Vlan_99,210-212,500>

========^

<command>vlan 99,210-212,500</command>

</Vlan_99,210-212,500>

I'm going to have to write a parser that will change that to <vlan name="Vlan_99,210-212,500"/>

1 Reply 1

mfreeman451
Level 1
Level 1

I've included some code that will help with these issues.. I haven't written a script yet to fix the vlan problems im having, but heres some other stuff..

The first one is a validator, run this through your .xml file to make sure it is well-formed, if its not, nothing will be able to parse it.

#!/usr/local/bin/perl

use XML::Parser;

my $xmlfile = shift @ARGV; # the file to parse

# initialize parser object and parse the string

my $parser = XML::Parser->new( ErrorContext => 2 );

eval { $parser->parsefile( $xmlfile ); };

# report any error that stopped parsing, or announce success

if( $@ ) {

$@ =~ s/at \/.*?$//s; # remove module line number

print STDERR "\nERROR in '$file':\n$@\n";

} else {

print STDERR "$xmlfile is well-formed\n";

}

I'm not really sure if this 2nd one is going to be useful for anybody. The first time I used DEE, someone sent me all of the data in an .xls spreadsheet, which I then promptly converted to .csv, so it may have been excel mangling the XML data.. not really sure, but maybe it will be useful:

use strict;

my $xmlfile = shift @ARGV;

#undef $/; # suck in whole file for each read

my($no_desc,$found_desc,$descstring);

my($no_romver,$found_romver,$romstring);

open(F, "$xmlfile") or die("Couldn't open XML file: $!\n");

while() {

chomp;

# strip out quotes

$_ =~ s/""/"/g;

# rip out leading and trailing quotes

$_ =~ s/"

$_ =~ s/>"/>/g;

# remove whitespace garbage bullshit

$_ =~ s/value=\"(.*?)\s+\">/value=\"$1\">/g;

# fix whitespace / newline issues

$_ =~ s/value=\"(.*)\"><\/AD>$/value=\"$1\"><\/AD>/gs;

#$ fix sysobjectid tag

$_ =~ s/(.*?)?\s+/$1/g;

# code to fix the broken ass description tag

if ($_ =~ m/^/) { # match the beginning of the Tag

$found_desc = 1;

}

$descstring .= $_ if ($found_desc); # match anything inside the tag

if ($_ =~ m/<\/Description>/) { # End of the tag

$descstring =~ s/\n/\s/g; # replace newlines with spaces

$descstring =~ s/"/\s/g; # remove quotes that might be in middle?

# put quotes in front and end of string

$descstring =~ s/(.*)<\/Description>/\"$1\"<\/Description>/;

print "$descstring\n";

# reset our variables..

$no_desc = 1;

$found_desc = 0;

undef $descstring;

next;

}

next if ($found_desc);

# code to fix the broken as

$found_romver = 1;

}

$romstring .= $_ if ($found_romver); # inside of

# fix the broken romstring..

if ($_ =~ m/^\"><\/AD>/) { # end of

$romstring =~ s/\"\"//g;

$romstring =~ s/value=\"(.*)><\/AD>/value=\"$1\"><\/AD>/;

print "$romstring\n";

$found_romver = 0;

undef $romstring;

next;

}

next if ($found_romver);

# Fix shit for missing quote on ConfigReg thing

$_ =~ s/AD name=ConfigReg\"/AD name=\"ConfigReg\"/;

print "$_\n";

}