From 684e3d84b6d054164892330618ab1531b1c5a291 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Thu, 21 Jul 2011 11:55:31 +0200 Subject: [PATCH] Fix 'zypper search' xml output (bnc#687529) --- src/Table.h | 2 ++ src/output/OutXML.cc | 31 ++++++++++++++++++++----------- src/search.cc | 4 ++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Table.h b/src/Table.h index 13e5508..22ec8dd 100644 --- a/src/Table.h +++ b/src/Table.h @@ -105,6 +105,8 @@ public: void allowAbbrev(unsigned column); void margin(unsigned margin); + const TableHeader & header() const + { return _header; } const container & rows() const { return _rows; } diff --git a/src/output/OutXML.cc b/src/output/OutXML.cc index 0cc042e..7a7f825 100644 --- a/src/output/OutXML.cc +++ b/src/output/OutXML.cc @@ -197,17 +197,26 @@ void OutXML::searchResult( const Table & table_r ) if ( ! rows.empty() ) { // - // *** CAUTION: It's a mess, but must mtch the header list defined + // *** CAUTION: It's a mess, but must match the header list defined // in FillSearchTableSolvable ctor (search.cc) - // - static const char * header[] = { - "status", - "name", - "kind", - "edition", - "arch", - "repository" - }; + // We derive the XML tag from the header, applying some translation + // hence and there. + std::vector header; + { + const TableHeader & theader( table_r.header() ); + for_( it, theader.columns().begin(), theader.columns().end() ) + { + if ( *it == "S" ) + header.push_back( "status" ); + else if ( *it == "Type" ) + header.push_back( "kind" ); + else if ( *it == "Version" ) + header.push_back( "edition" ); + else + header.push_back( zypp::str::toLower( *it ) ); + } + } + for_( it, rows.begin(), rows.end() ) { cout << "