I
I
Ilya2019-05-13 18:02:58
SQL Server
Ilya, 2019-05-13 18:02:58

How to form xml using sql?

I have an xml document like this:

<HeadNode>
    <information>
      <lastName>Иванов</lastName>
      <firstName>Иван</firstName>
      <birthDate>1900-01-01</birthDate>
      <gender>M</gender>
    </information>
    <documents>
      <document>
        <type>Passport</type>
        <number>123456</number>
        <issueDate>2000-01-01</issueDate>
      </document>
    </documents>
    <contacts>
      <contact>
        <type>Mphone</type>
        <phoneNumber>1234567890</phoneNumber>
      </contact>
      <contact>
        <type>Hphone</type>
        <phoneNumber>0987654321</phoneNumber>
        <region>
          <code>Odessa_region</code>
        </region>
        <city>
          <code>Odessa</code>
        </city>
      </contact>
      <contact>
        <type>Work</type>
        <region>
          <code>Odessa_region</code>
        </region>
        <city>
          <code>Odessa</code>
        </city>
      </contact>
    </contacts>
 </HeadNode>

How can I form it?
If possible, please provide some resources to study

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Tsvetkov, 2019-05-13
@tsklab

Google .

A
Antoshka1509, 2019-05-13
@Antoshka1509

$dbc = mysqli_connect($host, $username, $password, $database);
$data = mysqli_query($dbc, "SELECT * FROM users");
while ($row = mysqli_fetch_array($data)) {
    $res .= "<HeadNode>
    <information>
      <lastName>".$row['name']."</lastName>
      <firstName>".$row['lastname']."</firstName>
      <birthDate>".$row['bday']."</birthDate>
      <gender>".$row['gender']."</gender>
    </information>
    <documents>
      <document>
        <type>Passport</type>
        <number>".$row['number']."</number>
        <issueDate>".$row['date']."</issueDate>
      </document>
    </documents>
    <contacts>
      <contact>
        <type>Mphone</type>
        <phoneNumber>".$row['mphone']."</phoneNumber>
      </contact>
      <contact>
        <type>Hphone</type>
        <phoneNumber>".$row['hphone']."</phoneNumber>
        <region>
          <code>".$row['region']."</code>
        </region>
        <city>
          <code>".$row['city']."</code>
        </city>
      </contact>
      <contact>
        <type>Work</type>
        <region>
          <code>".$row['region']."</code>
        </region>
        <city>
          <code>".$row['city']."</code>
        </city>
      </contact>
    </contacts>
 </HeadNode>";
}
mysqli_close($dbc);
echo $res;

D
d-stream, 2019-05-13
@d-stream

Select ... from ... for xml actually

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question