$ xml = <<< EOF
<? xml version = "1.0" encoding = "UTF-8" ? >
< recipe name = βbreadβ preptime = β5β cooktime = β180β >
< title > Simple Bread </ title >
< ingredient amount = "3" unit = "glass" > Flour </ ingredient >
< ingredient amount = "0.25" unit = "gram" > Yeast </ ingredient >
< ingredient amount = "1.5" unit = "glass" > Warm water </ ingredient >
< ingredient amount = "1" unit = "teaspoon" > Salt </ ingredient >
< Instructions >
< step > Mix all ingredients and knead thoroughly. </ step >
< step > Cover with a cloth and leave for one hour in a warm room. </ step >
< step > Knead again, put on a baking sheet and put in the oven. </ step >
</ Instructions >
</ recipe >
EOF;
$ sx = new SimpleXMLElement ($ xml);
var_dump ($ sx); * This source code was highlighted with Source Code Highlighter .
object ( SimpleXMLElement ) [ 1 ]
public '@attributes' =>
array
'name' => string 'bread' (length = 8)
'preptime' => string '5' (length = 1)
'cooktime' => string '180' (length = 3)
public 'title' => string 'Simple bread' (length = 23)
public 'ingredient' =>
array
0 => string 'Flour' (length = 8)
1 => string 'Yeast' (length = 12)
2 => string 'Warm Water' (length = 21)
3 => string 'Salt' (length = 8)
public 'Instructions' =>
object ( SimpleXMLElement ) [ 2 ]
public 'step' =>
array
0 => string 'Mix all ingredients and knead thoroughly.' (length = 84)
1 => string 'Close with a cloth and leave for one hour in a warm room.' (length = 104)
2 => string 'Knead again, put on a baking sheet and put in the oven.' (length = 113)
<? xml version = "1.0" encoding = "UTF-8" ? > <? mso-application progid = "Excel.Sheet" ? >
< Workbook xmlns = "urn: schemas-microsoft-com: office: spreadsheet" xmlns: xsi = " www.w3.org/2001/XMLSchema-instance " xmlns: x = "urn: schemas-microsoft-com: office: excel " Xmlns: x2 =" schemas.microsoft.com/office/excel/2003/xml " xmlns: ss =" urn: schemas-microsoft-com: office: spreadsheet " xmlns: o =" urn: schemas-microsoft-com: office: office " xmlns: html =" www.w3.org/TR/REC-html40 " xmlns: c =" urn: schemas-microsoft-com: office: component: spreadsheet " >
< OfficeDocumentSettings xmlns = "urn: schemas-microsoft-com: office: office" >
< Colors >
< Color >
< Index > 3 </ Index >
< RGB > # c0c0c0 </ RGB >
</ Color >
< Color >
< Index > 4 </ Index >
< RGB > # ff0000 </ RGB >
</ Color >
</ Colors >
</ OfficeDocumentSettings >
< ExcelWorkbook xmlns = "urn: schemas-microsoft-com: office: excel" >
< WindowHeight > 9000 </ WindowHeight >
< WindowWidth > 13860 </ WindowWidth >
< WindowTopX > 240 </ WindowTopX >
< WindowTopY > 75 </ WindowTopY >
< ProtectStructure > False </ ProtectStructure >
< ProtectWindows > False </ ProtectWindows >
</ ExcelWorkbook >
< Styles >
< Style ss: ID = "Default" ss: Name = "Default" />
< Style ss: ID = "Result" ss: Name = "Result" >
< Font ss: Bold = "1" ss: Italic = "1" ss: Underline = "Single" />
</ Style >
< Style ss: ID = "Result2" ss: Name = "Result2" >
< Font ss: Bold = "1" ss: Italic = "1" ss: Underline = "Single" />
< NumberFormat ss: Format = "Currency" />
</ Style >
< Style ss: ID = "Heading" ss: Name = "Heading" >
< Alignment ss: Horizontal = "Center" />
< Font ss: Bold = "1" ss: Italic = "1" ss: Size = "16" />
</ Style >
< Style ss: ID = "Heading1" ss: Name = "Heading1" >
< Alignment ss: Horizontal = "Center" ss: Rotate = "90" />
< Font ss: Bold = "1" ss: Italic = "1" ss: Size = "16" />
</ Style >
< Style ss: ID = "co1" />
< Style ss: ID = "ta1" />
</ Styles >
< ss: Worksheet ss: Name = "Sheet1" >
< Table ss: StyleID = "ta1" >
< Column ss: Span = "2" ss: Width = "64.2614" />
< Row ss: Height = "12.1039" >
< Cell >
< Data ss: Type = "Number" > 1 </ Data >
</ Cell >
< Cell >
< Data ss: Type = "Number" > 2 </ Data >
</ Cell >
< Cell >
< Data ss: Type = "Number" > 3 </ Data >
</ Cell >
</ Row >
< Row ss: Height = "12.1039" >
< Cell >
< Data ss: Type = "Number" > 2 </ Data >
</ Cell >
< Cell ss: Formula = "= R [-1] C * RC1" >
< Data ss: Type = "Number" > 4 </ Data >
</ Cell >
< Cell ss: Formula = "= R [-1] C * RC1" >
< Data ss: Type = "Number" > 6 </ Data >
</ Cell >
</ Row >
< Row ss: Height = "12.1039" >
< Cell >
< Data ss: Type = "Number" > 3 </ Data >
</ Cell >
< Cell ss: Formula = "= R [-2] C * RC1" >
< Data ss: Type = "Number" > 6 </ Data >
</ Cell >
< Cell ss: Formula = "= R [-2] C * RC1" >
< Data ss: Type = "Number" > 9 </ Data >
</ Cell >
</ Row >
</ Table >
< x: WorksheetOptions />
</ ss: Worksheet >
< ss: Worksheet ss: Name = "Sheet2" >
< Table ss: StyleID = "ta1" >
< Column ss: Width = "64.2614" />
< Row ss: Height = "12.1039" >
< Cell ss: Index = "1" />
</ Row >
</ Table >
< x: WorksheetOptions />
</ ss: Worksheet >
< ss: Worksheet ss: Name = "Sheet3" >
< Table ss: StyleID = "ta1" >
< Column ss: Width = "64.2614" />
< Row ss: Height = "12.1039" >
< Cell ss: Index = "1" />
</ Row >
</ Table >
< x: WorksheetOptions />
</ ss: Worksheet >
</ Workbook > * This code was highlighted with Source Code Highlighter .
foreach ($ sx-> xpath ('// ss: Worksheet') as $ x) print_r ($ x);
xmlns = "urn: schemas-microsoft-com: office: spreads"
xmlns: xsi = " www.w3.org/2001/XMLSchema-instance "
xmlns: x = "urn: schemas-microsoft-com: office: excel"
xmlns: x2 = " schemas.microsoft.com/office/excel/2003/xml "
xmlns: ss = "urn: schemas-microsoft-com: office: spreads"
xmlns: o = "urn: schemas-microsoft-com: office: office"
xmlns: html = " www.w3.org/TR/REC-html40 "
xmlns: c = "urn: schemas-microsoft-com: office: component: spreads"
$ sx-> children ('urn: schemas-microsoft-com: office: spreadsheet') -> Worksheet
Source: https://habr.com/ru/post/37000/
All Articles