Bug #76072 mysql --xml with multiple queries produces invalid XML
Submitted: 26 Feb 2015 22:00 Modified: 27 Feb 2015 5:56
Reporter: Scott Noyes Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.6.22, 5.0.96, 5.1.73, 5.5.43, 5.6.25, 5.7.7, 8.0.0 OS:Any
Assigned to: CPU Architecture:Any

[26 Feb 2015 22:00] Scott Noyes
Description:
Running multiple queries produces malformed XML.
- The XML declaration is written before each result set.
- There is no single root element encapsulating all resultset elements.

How to repeat:
mysql --xml -e "select 1; select 2;"

Produces:

<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>

Suggested fix:
- The XML declaration should only be written once, at the very beginning.
- There should be a single root element containing all resultsets.
[27 Feb 2015 5:56] Umesh Shastry
Hello Scott,

Thank you for the report.
Confirmed that this behavior in latest builds of 5.0, 5.1, 5.5, 5.6, 5.7 and trunk builds.

Thanks,
Umesh
[27 Feb 2015 5:57] Umesh Shastry
// 5.0.96

[ushastry@ushastry]/export/umesh/mysql-5.0.96: bin/mysql -S /tmp/mysql_ushastry.sock --xml -e "select 1; select 2;"
<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>

// 5.1.73

[ushastry@ushastry]/export/umesh/mysql-5.1.73: bin/mysql -S /tmp/mysql_ushastry.sock --xml -e "select 1; select 2;"
<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>

// 5.5.43

[ushastry@ushastry]/export/umesh/mysql-5.5.43: bin/mysql -S /tmp/mysql_ushastry.sock --xml -e "select 1; select 2;"
<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>

// 5.6.25

[ushastry@ushastry]/export/umesh/mysql-5.6.25:  bin/mysql -S /tmp/mysql_ushastry.sock --xml -e "select 1; select 2;"
<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>

// 5.7.7

[ushastry@ushastry]/export/umesh/mysql-5.7.7:  bin/mysql -uroot -S /tmp/mysql_ushastry.sock --xml -e "select 1; select 2;"
<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>

// 5/8/0

[ushastry@ushastry]/export/umesh/mysql-5.8.0: bin/mysql -uroot -S /tmp/mysql_ushastry.sock --xml -e "select 1; select 2;"
<?xml version="1.0"?>

<resultset statement="select 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="1">1</field>
  </row>
</resultset>
<?xml version="1.0"?>

<resultset statement="select 2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
        <field name="2">2</field>
  </row>
</resultset>
[18 Jun 2016 21:24] Omer Barnir
Posted by developer:
 
Reported version value updated to reflect release name change from 5.8 to 8.0