B
B
banny_name2015-08-28 17:37:05
PHP
banny_name, 2015-08-28 17:37:05

How to parse such xml document?

there is a string (obtained from the document), a string, because some work has already been done with it.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" mc:Ignorable="w14 wp14">
<w:body>
  <w:p>
      <w:r>
        <w:rPr>
          <w:lang w:val="ru-RU"/>
        </w:rPr>
        <w:t xml:space="preserve">Кому: </w:t>
        </w:r>
        <w:r>
          <w:rPr>
            <w:lang w:val="en-US"/>
          </w:rPr>
            <w:t>Search</w:t>
        </w:r>
        <w:r>
          <w:rPr>
            <w:lang w:val="ru-RU"/>
          </w:rPr>
          <w:br/>
          <w:t xml:space="preserve">Куда: </w:t>
        </w:r>
        <w:r></w:r>
    </w:p>
  </w:body>
</w:document>

I do:
simplexml_load_string(эта строка)
Result:
object(SimpleXMLElement)#1 (0) {
}

How to parse correctly?
and get everything in between

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Pasechnik, 2015-08-28
@jumper423

This will suit xml_parse_into_struct

E
Eugene, 2015-08-28
@Nc_Soft

Give direction where to dig

$xml = simplexml_load_string($data);
var_dump(
    $xml->children('w', true)->body
        ->children('w', true)->p
        ->children('w', true)->r
        ->children('w', true)->rPr
        ->children('w', true)->lang
);

In general, for parsing docx it is better to use PHPExcel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question