Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: przetwazanie pliku XML
Forum PHP.pl > Forum > Przedszkole
Guest
chce przetwozyc plik XML a dkoladnie generowany przez Excel wiec wczytuje go przez simplexml i che sie dobrac do atrybutow ale maja one taka postac:
Kod
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="4" x:FullColumns="1"
   x:FullRows="1">
   <Row>
    <Cell><Data ss:Type="String">kolumna1</Data></Cell>
    <Cell ss:MergeAcross="1"><Data ss:Type="String">kolumna2_zlacz</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">aaa</Data></Cell>
    <Cell><Data ss:Type="String">bbbb</Data></Cell>
    <Cell><Data ss:Type="String">ccc</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">SSS</Data></Cell>
    <Cell><Data ss:Type="String">SWE</Data></Cell>
    <Cell><Data ss:Type="String">TEST</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">asas</Data></Cell>
    <Cell><Data ss:Type="String">adad</Data></Cell>
    <Cell><Data ss:Type="String">afaf</Data></Cell>
   </Row>
  </Table>


nie wiem jak sie dobrac do ss:ExpandedColumnCount
  1. <?php
  2. $xml = simplexml_load_file('test.xml');
  3. echo $xml->Table['ExpandedColumnCount'];
  4.  
  5. ?>
to cos takiego nie dziala sad.gif jak dam $xml->Table['ss:ExpandedColumnCount']; to tez nie sad.gif wiec jak mam sie do tego dobrac?questionmark.gif
tiraeth
Z tego co widzę po Twoim kodzie php to $xml->Table jest tablicą. Może poprostu potraktuj ją print_r($xml->Table); ?
NuLL
  1. <?php
  2. $xml = simplexml_load_file('test.xml');
  3. echo (string)$xml->Table->ExpandedColumnCount;
  4.  
  5. ?>

@tiraeth - nie tablica - ja juz to iteratorem.

Zdravim
aleksander
najwyższy tag jest jako najwyższy obiekt SimpleXML. czytaj: tag table jest obiektem zapisanym w zmiennej $xml czyli:
zamiast $xml->Table['ExpandedColumnCount']
bedzie $xml['ExpandedColumnCount'];
Guest
hmm tag wyglada tak:
Kod
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="4" x:FullColumns="1"
  x:FullRows="1">
ja che sie dostac do ss:ExpandedColumnCount czyli otrzymac wartosc 3 smile.gif
aleksander
$xml['ss:ExpandedColumnCount'] questionmark.gif
dr_bonzo
Kod aleksandra powinien dzialac, ale nie dziala. Nawet DOMem nie moglem odczytac tego atrybutu -- nie ma takiej opcji.
Guest
niebardzo sad.gif

caly plik XML wyglada tak:
  1. <?xml version="1.0"?>
  2. <?mso-application progid="Excel.Sheet"?>
  3. <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  4. xmlns:o="urn:schemas-microsoft-com:office:office"
  5. xmlns:x="urn:schemas-microsoft-com:office:excel"
  6. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  7. xmlns:html="http://www.w3.org/TR/REC-html40">
  8. <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  9. <Author>zzz</Author>
  10. <LastAuthor>zzz</LastAuthor>
  11. <Created>2006-01-15T14:03:24Z</Created>
  12. <Company>niepowiem</Company>
  13. <Version>11.6505</Version>
  14. </DocumentProperties>
  15. <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  16. <WindowHeight>13185</WindowHeight>
  17. <WindowWidth>15120</WindowWidth>
  18. <WindowTopX>480</WindowTopX>
  19. <WindowTopY>30</WindowTopY>
  20. <ProtectStructure>False</ProtectStructure>
  21. <ProtectWindows>False</ProtectWindows>
  22. </ExcelWorkbook>
  23. <Styles>
  24. <Style ss:ID="Default" ss:Name="Normal">
  25. <Alignment ss:Vertical="Bottom"/>
  26. <Borders/>
  27. <Font x:CharSet="238"/>
  28. <Interior/>
  29. <NumberFormat/>
  30. <Protection/>
  31. </Style>
  32. </Styles>
  33. <Worksheet ss:Name="Arkusz1">
  34. <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1">
  35. <Row>
  36. <Cell><Data ss:Type="String">kolumna 1</Data></Cell>
  37. <Cell><Data ss:Type="String">kolumna 2</Data></Cell>
  38. <Cell><Data ss:Type="String">kolumna 3</Data></Cell>
  39. </Row>
  40. <Row>
  41. <Cell><Data ss:Type="String">aaa</Data></Cell>
  42. <Cell><Data ss:Type="String">bbbb</Data></Cell>
  43. <Cell><Data ss:Type="String">cccc</Data></Cell>
  44. </Row>
  45. <Row>
  46. <Cell><Data ss:Type="String">1q1q1q</Data></Cell>
  47. <Cell><Data ss:Type="String">2w2w2w</Data></Cell>
  48. <Cell><Data ss:Type="String">3e3e3e</Data></Cell>
  49. </Row>
  50. <Row>
  51. <Cell><Data ss:Type="String">zzz</Data></Cell>
  52. <Cell><Data ss:Type="String">xxx</Data></Cell>
  53. <Cell><Data ss:Type="String">qqq</Data></Cell>
  54. </Row>
  55. </Table>
  56. <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
  57. <PageSetup>
  58. <PageMargins x:Bottom="0.984251969" x:Left="0.78740157499999996"
  59. x:Right="0.78740157499999996" x:Top="0.984251969"/>
  60. </PageSetup>
  61. <Selected/>
  62. <ProtectObjects>False</ProtectObjects>
  63. <ProtectScenarios>False</ProtectScenarios>
  64. </WorksheetOptions>
  65. </Worksheet>
  66. </Workbook>


jest to prosty plik excel zapisany jako xml smile.gif chce wyciagnac z niego miedzy innymi to ss:ExpandedColumnCount="3" a dokladnie wartosc 3 smile.gif
  1. <?php
  2.  
  3. $xml = simplexml_load_file('excel.xml');
  4. echo $xml->DocumentProperties->Worksheet->Table['ss:ExpandedColumnCount'];
  5. ?>
to nie dziala sad.gif ani $xml->DocumentProperties->Worksheet->Table['ExpandedColumnCount'];
dr_bonzo
Teraz to co innego biggrin.gif.

  1. <?php
  2. $xml = simplexml_load_string( $xmlData );
  3. $attributes = $xml->Worksheet->Table->attributes( 'urn:schemas-microsoft-com:office:spreadsheet' );
  4. $cols = $attributes[ 'ExpandedColumnCount' ];
  5. print( $cols );
  6.  
  7. ?>


Gotcha biggrin.gif

A wszystko to bylo tutaj (w manualu tez tongue.gif):
http://www.sitepoint.com/blogs/2005/10/20/...and-namespaces/
Guest
dzieki dr_bonzo dziala smile.gif

zapewne sie domyslacie po co to robie smile.gif bo chce w latwy sposob prezentowac arkusze zrobione w Excelu lub OpenOffice Calc na strocnie smile.gif narazie mam bardzo prototypowy skrypt ale potrafi paczyc komorki oraz wiersze oraz formatowac komorki (tlo, czcionka, polozenie textu) moze juz sa jakies gotowe komponenty do tego jakas klasa albo cos smile.gif

jesli nie moge zaprezentowac to co mam smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.