Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: problem z wyświtlaniem danych miedzy tagami
Forum PHP.pl > Forum > XML, AJAX > XML
gxw
Mam problem-nie wyświetlają mi się dane z XML-a jeżli chce tylko wyświetlić zdanego tag-a, jak chce wyświtlić wszystko na raz to nie ma problemu. Dzieję się to tylko przy typie dokumentów tworzonych przy specyfikacji? eBIS-XML (tworzy je program SUBIEKT GT). Kod php działa bo inne dokumenty wyświetla bez problemu. Poniżej zamieszczam kod takiego problematycznego dokumentu-jakby komuś się udało wyświetlić dane z jakiegokolwiek znacznika (nie całość) to byłbym wdzięczny o wskazówki. Używam php 4.3.11
Dzięki, pozdrawiam
Kod
  <?xml version="1.0" encoding="windows-1250" ?>
  <?xml-stylesheet type="text/xsl" href=""?>
- <Batch xmlns="urn:schemas-basda-org:BatchEnvelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Date="2005-08-23" Number="1" SupplierName="KRZAK Sp.zo.o." DocType="Invoice">
- <Invoice xmlns="urn:schemas-basda-org:2000:salesInvoice:xdr:3.01">
- <InvoiceHead xmlns="">
- <Schema>
  <Version>3</Version>
  </Schema>
- <Parameters>
  <Language>PL</Language>
  <DecimalSeparator>,</DecimalSeparator>
  <Precision>20.3</Precision>
  </Parameters>
  <InvoiceType Code="INV">Dokument VAT</InvoiceType>
  <Function Code="FII" />
- <InvoiceCurrency>
  <Currency Code="PLN" />
  </InvoiceCurrency>
  <Checksum>65300</Checksum>
  </InvoiceHead>
- <InvoiceReferences xmlns="">
  <SuppliersInvoiceNumber>99999/2005</SuppliersInvoiceNumber>
  </InvoiceReferences>
  <InvoiceDate xmlns="">2010-01-01</InvoiceDate>
  <CityOfIssue xmlns="">WARSZAWA</CityOfIssue>
  <TaxPointDate xmlns="">2010-01-01</TaxPointDate>
- <Supplier xmlns="">
- <SupplierReferences>
  <BuyersCodeForSupplier>FLD</BuyersCodeForSupplier>
  <TaxNumber>555-88-462-55</TaxNumber>
  </SupplierReferences>
  <Party>Krzak Sp.z o.o.</Party>
- <Address>
  <Street>Fabryczna 156/25</Street>
  <City>WARSZAWA</City>
  <PostCode>05-888</PostCode>
  </Address>
- <Contact>
  <Name>Jan Kos</Name>
  <Switchboard>555 55 55</Switchboard>
  <Fax>555 55 55</Fax>
  </Contact>
  </Supplier>
- <Buyer xmlns="">
- <BuyerReferences>
  <SuppliersCodeForBuyer>KOD FIRMY</SuppliersCodeForBuyer>
  <TaxNumber>125-444-6334</TaxNumber>
  </BuyerReferences>
  <Party>WICE KRZAK</Party>
- <Address>
  <Street>UL.Burakowo 17</Street>
  <City>NOWY SAD</City>
  <PostCode>10-555</PostCode>
  </Address>
- <Contact>
  <Name />
  <Switchboard />
  <Fax />
  </Contact>
  </Buyer>
- <InvoiceLine xmlns="">
  <LineNumber>1</LineNumber>
- <Product>
  <SuppliersProductCode>KOD PRODUKTU</SuppliersProductCode>
  <Description>NAZWA PRODUKTU</Description>
  </Product>
- <Quantity UOMCode="szt.">
  <Packsize>1</Packsize>
  <Amount>1</Amount>
  </Quantity>
- <Price>
  <UnitPrice>1,3</UnitPrice>
  </Price>
- <PercentDiscount>
  <Type Code="LID" />
  <Percentage>0</Percentage>
  </PercentDiscount>
- <LineTax>
  <TaxRate Code="S">22</TaxRate>
  <TaxValue>0,29</TaxValue>
  </LineTax>
  <LineTotal>1,59</LineTotal>
  <InvoiceLineInformation />
  </InvoiceLine>
  <Narrative xmlns="" />
  <SpecialInstructions xmlns="">dokument liczony wg cen netto</SpecialInstructions>
- <Settlement xmlns="">
  <SettlementTerms Code="30I">2010-01-01</SettlementTerms>
  </Settlement>
- <TaxSubTotal xmlns="" Code="PLN">
  <TaxRate Code="S">22</TaxRate>
  <TaxableValueAtRate>1,3</TaxableValueAtRate>
  <TaxAtRate>0,29</TaxAtRate>
  <NetPaymentAtRate>1,59</NetPaymentAtRate>
  <GrossPaymentAtRate>1,59</GrossPaymentAtRate>
  <TaxCurrency />
  </TaxSubTotal>
- <InvoiceTotal xmlns="">
  <NumberOfLines>1</NumberOfLines>
  <NumberOfTaxRates>1</NumberOfTaxRates>
  <LineValueTotal>1,3</LineValueTotal>
  <TaxableTotal>1,3</TaxableTotal>
  <TaxTotal>0,29</TaxTotal>
  <NetPaymentTotal>1,59</NetPaymentTotal>
  <GrossPaymentTotal>1,59</GrossPaymentTotal>
  </InvoiceTotal>
  </Invoice>
- <BatchTrailer xmlns="">
- <ItemCurrency>
  <Currency Code="PLN" />
  </ItemCurrency>
  <Checksum />
  </BatchTrailer>
  </Batch>
Sh4dow
pierwszepytanie czy do parasera wpleiles ten kod co podales tutaj czy podales sciezke do pliku wygenerowanego przez program. Jesli to co wkleiles to sie nie dziwie. Jest to kopia wyswietlana przez przegladarke, gdzie skopiowales znaczki "-" ktore sluza do zwijania blokow. A to nie przejdzie.
Czy otrzymujesz jakies bledy przy probie generowania tego ?
Czy posiadasz jakis szablon xsl do tego ?
Probowales przeparasowac to do tablicy php i zobaczyc czy posiada ona jakies wartosci ?
prosty skrypcik xml2array masz tutaj ale to tylko dla php5
xml wyglad na dobry, ale jakos nie mam sil wstawiac tabulatorow i usuwac 'minusikow' wiec poprobuj bedzie ci latwiej.
gxw
1. podaje scieżke do pliku
2. tworze klase - potem switch case i jak trafi na zadany znacznik to wbija zawartość do tablicy i potem wyświetlam po kolei z tablicy
3. inne pliki xmla działają bez problemu-tylko ten typ
4. kod który wkleiłem jest z podglądu z IE-może troche poszedłem na łatwizne teraz wklejam lepszy-powinno dzialc
5. chodzi mi tylko aby dobrac sie do danych ale nie wcałości (a najdokladniej interesują mnie dane pomiedzy znacznikami InvoiceLine)
6. jakbyś mogł pomóc to z góry dziękuję
Pozdrawiam


  1. <?xml version="1.0" encoding="windows-1250"?>
  2. <?xml-stylesheet type="text/xsl" href=""?>
  3. <Batch xmlns="urn:schemas-basda-org:BatchEnvelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Date="2005-08-23" Number="1" SupplierName="KRZAK" DocType="Invoice"><Invoice xmlns="urn:schemas-basda-org:2000:salesInvoice:haha.gifr:3.01"><InvoiceHead xmlns=""><Schema><Version>3</Version></Schema><Parameters><Language>PL</Language><DecimalSeparator>,</DecimalSeparator><Precision>20.3</Precision></Parameters><InvoiceType Code="INV">Faktura VAT</InvoiceType><Function Code="FII"></Function><InvoiceCurrency><Currency Code="PLN"/></InvoiceCurrency><Checksum>65300</Checksum></InvoiceHead><InvoiceReferences xmlns=""><SuppliersInvoiceNumber>8374/2005</SuppliersInvoiceNumber></InvoiceReferences><InvoiceDate xmlns="">2005-07-11</InvoiceDate><CityOfIssue xmlns="">WARSZAWA</CityOfIssue><TaxPointDate xmlns="">2005-07-11</TaxPointDate><Supplier xmlns=""><SupplierReferences><BuyersCodeForSupplier>GMD</BuyersCodeForSupplier><TaxNumber>666-55-55-66</TaxNumber></SupplierReferences><Party>KRZAK</Party><Address><Street>JANÓW 25</Street><City>WARSZAWA</City><PostCode>05-666</PostCode></Address><Contact><Name>JAN KOS</Name><Switchboard>699 99 99</Switchboard><Fax>699 99 99</Fax></Contact></Supplier><Buyer xmlns=""><BuyerReferences><SuppliersCodeForBuyer>COLOR</SuppliersCodeForBuyer><TaxNumber>134-555-66</TaxNumber></BuyerReferences><Party>COLOR SP.Z00</Party><Address><Street>UL.PAŁKI 17 </Street><City>NOWY SAD</City><PostCode>33-300</PostCode></Address><Contact><Name></Name><Switchboard></Switchboard><Fax></Fax></Contact></Buyer><InvoiceLine xmlns=""><LineNumber>1</LineNumber><Product><SuppliersProductCode>MC-PŁYT</SuppliersProductCode><Description>PŁYTY BRUKOWE</Description></Product><Quantity UOMCode="szt."><Packsize>1</Packsize><Amount>1</Amount></Quantity><Price><UnitPrice>1,3</UnitPrice></Price><PercentDiscount><Type Code="LID"/><Percentage>0</Percentage></PercentDiscount><LineTax><TaxRate Code="S">22</TaxRate><TaxValue>0,29</TaxValue></LineTax><LineTotal>1,59</LineTotal><InvoiceLineInformation></InvoiceLineInformation></InvoiceLine><Narrative xmlns=""></Narrative><SpecialInstructions xmlns="">dokument liczony wg cen netto</SpecialInstructions><Settlement xmlns=""><SettlementTerms Code="30I">2005-08-10</SettlementTerms></Settlement><TaxSubTotal xmlns="" Code="PLN"><TaxRate Code="S">22</TaxRate><TaxableValueAtRate>1,3</TaxableValueAtRate><TaxAtRate>0,29</TaxAtRate><NetPaymentAtRate>1,59</NetPaymentAtRate><GrossPaymentAtRate>1,59</GrossPaymentAtRate><TaxCurrency/></TaxSubTotal><InvoiceTotal xmlns=""><NumberOfLines>1</NumberOfLines><NumberOfTaxRates>1</NumberOfTaxRates><LineValueTotal>1,3</LineValueTotal><TaxableTotal>1,3</TaxableTotal><TaxTotal>0,29</TaxTotal><NetPaymentTotal>1,59</NetPaymentTotal><GrossPaymentTotal>1,59</GrossPaymentTotal></InvoiceTotal></Invoice><BatchTrailer xmlns=""><ItemCurrency><Currency Code="PLN"/></ItemCurrency><Checksum/></BatchTrailer></Batch>
Sh4dow
moze to ci pomoze u mnie przeszlo bez problemow. Klasa to nie orginal ktory uzywam bo jest wyciagnieta z moejgo systemiku gdzie mam inne klasy obslugujace naprzyklad pliki itd. No niewazne. Nie mam do tego jakiegos przyjaznego interfejsuzeby mozna bylo czytac i szuac. ale sadze ze dasz sobie rade.
U mnie twoj plik xml przeszedl, ale mialem dosc pogmatwana tablice. Dlatego mowilem ze przydal by sie do tego interface, ktorego ja niestety jeszcze nie mam. Zycze powodzenia. Rkingsmiley.png
  1. <?php
  2.  
  3. /**
  4.  * Opis: Klasa przetwarzajaca xml do postaci tablicy
  5.  *
  6.  * @author Tomasz 'Sh4dow' Budzynski <sh4dow@php.pl>
  7.  * @version 0.4.6
  8.  */
  9. class XmlParser {
  10.  
  11.  /**
  12. * Tablica z danymi pliku xml po parsowaniu
  13. *
  14. * @var array
  15. */
  16.  private $arrOutput = array();
  17.  
  18.  /**
  19. * Enter description here...
  20. *
  21. * @var resorce
  22. */
  23.  private $resParser;
  24.  
  25.  /**
  26. * Enter description here...
  27. *
  28. * @var string
  29. */
  30.  private $strXmlData;
  31.  
  32. /**
  33.  * odczyt pliku xml
  34.  *
  35.  * @param string $strFilePath
  36.  * @return array
  37.  */
  38. function readFile ( $strFilePath ) {
  39. $strFileBody = file_get_contents( $strFilePath );
  40. return $this->parse( $strFileBody );
  41. }
  42.  
  43. /**
  44.  * paraser przetwarzajacy string xml
  45.  *
  46.  * @param string $strInputXML
  47.  * @return array
  48.  */
  49. function parse( $strInputXML ) {
  50.  
  51. $this->resParser = xml_parser_create();
  52. xml_set_object( $this->resParser, $this );
  53. xml_set_element_handler( $this->resParser, "tagOpen", "tagClosed" );
  54.  
  55. xml_set_character_data_handler( $this->resParser, "tagData" );
  56.  
  57. $this->strXmlData = xml_parse( $this->resParser, $strInputXML );
  58. if( !$this->strXmlData ) {
  59. die( sprintf( "Blad !! %s at line %d",
  60. xml_error_string( xml_get_error_code( $this->resParser ) ),
  61. xml_get_current_line_number( $this->resParser ) ) );
  62. }
  63. xml_parser_free( $this->resParser );
  64.  
  65. return $this->arrOutput;
  66. }
  67.  
  68.  /**
  69. * tag otwierający
  70. *
  71. * @param unknown_type $parser
  72. * @param string $name
  73. * @param string $att
  74. */
  75.  function tagOpen( $parser, $name, $att ) {
  76.  $tag = array( "tag_name" => $name, "tag_attr" => $att );
  77.  array_push( $this->arrOutput, $tag );
  78.  }
  79.  
  80.  /**
  81. * Dane 
  82. *
  83. * @param unknown_type $parser
  84. * @param string $tagData
  85. */
  86.  function tagData( $parser, $tagData ) {
  87.  if( trim( $tagData )) {
  88.  if( isset( $this->arrOutput[ count( $this->arrOutput ) - 1 ]['tagData'] ) ) {
  89.  $this->arrOutput[ count( $this->arrOutput ) - 1 ]['tagData'] .= $tagData;
  90.  }
  91.  else {
  92.  $this->arrOutput[ count ( $this->arrOutput ) - 1 ]['tagData'] = $tagData;
  93.  }
  94.  }
  95.  }
  96.  
  97.  /**
  98. * Metoda zamykajaca tagi xml
  99. *
  100. * @param unknown_type $parser
  101. * @param string $name
  102. */
  103.  function tagClosed($parser, $name) {
  104.  $this->arrOutput[ count( $this->arrOutput ) - 2 ]['children'][] = $this->arrOutput[ count( $this->arrOutput ) - 1 ];
  105.  array_pop( $this->arrOutput );
  106.  }
  107. }
  108.  
  109. $xml = New XmlParser();
  110. var_dump( $xml->readFile('plik.xml') ); 
  111. ?>
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.