Kernel::System::XML - xml lib
All xml related functions.
Don't use the constructor directly, use the ObjectManager instead:
my $XMLObject = $Kernel::OM->Get('Kernel::System::XML');
add an XMLHash to storage
my $Key = $XMLObject->XMLHashAdd( Type => 'SomeType', Key => '123', XMLHash => \@XMLHash, ); my $AutoKey = $XMLObject->XMLHashAdd( Type => 'SomeType', KeyAutoIncrement => 1, XMLHash => \@XMLHash, );
update an XMLHash to storage
$XMLHash[1]->{Name}->[1]->{Content} = 'Some Name'; $XMLObject->XMLHashUpdate( Type => 'SomeType', Key => '123', XMLHash => \@XMLHash, );
get an XMLHash from the database
my @XMLHash = $XMLObject->XMLHashGet( Type => 'SomeType', Key => '123', ); my @XMLHash = $XMLObject->XMLHashGet( Type => 'SomeType', Key => '123', Cache => 0, # (optional) do not use cached data );
delete an XMLHash from the database
$XMLObject->XMLHashDelete( Type => 'SomeType', Key => '123', );
move an XMLHash from one type or/and key to another
$XMLObject->XMLHashMove( OldType => 'SomeType', OldKey => '123', NewType => 'NewType', NewKey => '321', );
Search an XMLHash in the database.
my @Keys = $XMLObject->XMLHashSearch( Type => 'SomeType', What => [ # each array element is a and condition { # or condition in hash "[%]{'ElementA'}[%]{'ElementB'}[%]{'Content'}" => '%contentA%', "[%]{'ElementA'}[%]{'ElementC'}[%]{'Content'}" => '%contentA%', }, { "[%]{'ElementA'}[%]{'ElementB'}[%]{'Content'}" => '%contentB%', "[%]{'ElementA'}[%]{'ElementC'}[%]{'Content'}" => '%contentB%', }, { # use array reference if different content with same key was searched "[%]{'ElementA'}[%]{'ElementB'}[%]{'Content'}" => ['%contentC%', '%contentD%', '%contentE%'], "[%]{'ElementA'}[%]{'ElementC'}[%]{'Content'}" => ['%contentC%', '%contentD%', '%contentE%'], }, ], );
generate a list of XMLHashes in the database
my @Keys = $XMLObject->XMLHashList( Type => 'SomeType', );
generate an XML string from an XMLHash
my $XMLString = $XMLObject->XMLHash2XML(@XMLHash);
parse an XML file and return an XMLHash structure
my @XMLHash = $XMLObject->XMLParse2XMLHash( String => $FileString ); XML: ==== <Contact role="admin" type="organization"> <Name type="long">Example Inc.</Name> <Email type="primary">info@exampe.com<Domain>1234.com</Domain></Email> <Email type="secondary">sales@example.com</Email> <Telephone country="germany">+49-999-99999</Telephone> </Contact> ARRAY: ====== @XMLHash = ( undef, { Contact => [ undef, { role => 'admin', type => 'organization', Name => [ undef, { Content => 'Example Inc.', type => 'long', }, ], Email => [ undef, { type => 'primary', Content => 'info@exampe.com', Domain => [ undef, { Content => '1234.com', }, ], }, { type => 'secondary', Content => 'sales@exampe.com', }, ], Telephone => [ undef, { country => 'germany', Content => '+49-999-99999', }, ], } ], } ); $XMLHash[1]{Contact}[1]{TagKey} = "[1]{'Contact'}[1]"; $XMLHash[1]{Contact}[1]{role} = "admin"; $XMLHash[1]{Contact}[1]{type} = "organization"; $XMLHash[1]{Contact}[1]{Name}[1]{TagKey} = "[1]{'Contact'}[1]{'Name'}[1]"; $XMLHash[1]{Contact}[1]{Name}[1]{Content} = "Example Inc."; $XMLHash[1]{Contact}[1]{Name}[1]{type} = "long"; $XMLHash[1]{Contact}[1]{Email}[1]{TagKey} = "[1]{'Contact'}[1]{'Email'}[1]"; $XMLHash[1]{Contact}[1]{Email}[1]{Content} = "info\@exampe.com"; $XMLHash[1]{Contact}[1]{Email}[1]{Domain}[1]{TagKey} = "[1]{'Contact'}[1]{'Email'}[1]{'Domain'}[1]"; $XMLHash[1]{Contact}[1]{Email}[1]{Domain}[1]{Content} = "1234.com"; $XMLHash[1]{Contact}[1]{Email}[2]{TagKey} = "[1]{'Contact'}[1]{'Email'}[2]"; $XMLHash[1]{Contact}[1]{Email}[2]{type} = "secondary"; $XMLHash[1]{Contact}[1]{Email}[2]{Content} = "sales\@exampe.com";
returns a simple hash with tag keys as keys and the values of XMLHash
as values. As a side effect the data structure XMLHash
is enriched with tag keys.
my %Hash = $XMLObject->XMLHash2D( XMLHash => \@XMLHash );
For example:
$Hash{"[1]{'Planet'}[1]{'Content'}"'} = 'Sun';
get an @XMLHash from a @XMLStructure with current TagKey param
my @XMLHash = $XMLObject->XMLStructure2XMLHash( XMLStructure => \@XMLStructure );
parse an XML file
my @XMLStructure = $XMLObject->XMLParse( String => $FileString ); my @XMLStructure = $XMLObject->XMLParse( String => \$FileStringScalar );
This software is part of the OTRS project (https://otrs.org/).
This software comes with ABSOLUTELY NO WARRANTY. For details, see the enclosed file COPYING for license information (GPL). If you did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.