PHP Parsing XML documents

Source: Internet
Author: User

3

0


2013-12-01 23:42
From Dongguan Shatin Branch to Dongguan Company


2013-12-02 00:35
Express has arrived in Dongguan company scanner is Li Yuewen on a station is a branch in Shatin, Dongguan

<
Time>2013-12-02 01:35
Sent by Dongguan Company to Chengdu Distribution Center


2013-12-03 18:41
Express has arrived in Chengdu Distribution center scanner is Li Han soldiers on a stop is Dongguan company
2013-12-03 20:27
Sent by Chengdu Distribution Center to Dazhou (0818-2660770)


2013-12-04 12:58
Shipment has arrived Dazhou (0818-2660770) the scanner is 81800. Previous station is Chengdu Distribution Center


2013-12-04 13:24
Sent by Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
2013-12-04 16:32
Shipment has arrived Dazhu (0818-6259812,15908382116) The scanner is 81801 on the previous stop is Dazhou (0818-2660770)


2013-12-04 16:32
0818-6259812,15908382116 's dispatch officer, 88th, is sending a piece.


2013-12-04 16:33
0818-6259812,15908382116 is conducting a shipment retention scan


2013-12-06 12:43
has been signed, the signature is the person I



580038002019
Daily Express
Tiantian
1386399373
4373
ASC


XML format, want to loop out the content inside the item!


Reply to discussion (solution)

Header (' content-type:text/html;charset=utf-8 '); $s =<<< XML
  
 
  
   
    3
   
  
  
   
  
  
   
    0
   
  
  
   
     
     2013-12-01 23:42 
     
       from Dongguan Shatin Branch to Dongguan company
      
 
 

    
   
   
     
     2013-12-02 00:35 
     
       Express has arrived in Dongguan company scanner is Li Yuewen on a station is a branch in Shatin, Dongguan
      
 
 

    
   
   
     
     2013-12-02 01:35 was
     
       sent to Chengdu Distribution Center by Dongguan company
      
 
 

    
   
   
     
     2013-12-03 18:41 
     
       Express has arrived in Chengdu Distribution center scanner is Li Han soldiers on a stop is Dongguan company
      
 
 

    
   
   
     
     2013-12-03 20:27 
     
       from Chengdu Distribution Center sent to Dazhou (0818-2660770)
      
 
 

    
   
   
     
     2013-12-04 12:58 
     
       Express has arrived Dazhou (0818-2660770) The scanner is 81800 the previous station is Chengdu Distribution Center
      
 
 

    
   
   
     
     2013-12-04 13:24 
     
       from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
      
 
 

    
   
   
     
     2013-12-04 16:32 
     
       Express has reached Dazhu (0818-6259812,15908382116) scanner is 81801 previous stop is Dazhou (0818-2660770)
      
 
 

    
   
   
     
     2013-12-04 16:32 
     
       (0818-6259812,15908382116), dispatch, 88th, is sending a piece.
      
 
 

    
   
   
     
     2013-12-04 16:33 da Zhu
     
       (0818-6259812,15908382116) is in the shipment keeping position scanning
      
 
 

    
   
   
     
     2013-12-06 12:43 
     
       has signed, the sign is my
      
 
 

    
   
  
   
    580038002019
   
  
  
   
    Daily Express
   
  
  
   
    Tiantian
   
  
  
   
    1386399373
   
  
  
   
    4373
   
  
  
   
    ASC
   
  
 XML, $xml = simplexml_load_string ($s), foreach ($xml->xpath ('//item ') as $item) {echo $item->time, ', $item->co ntext, Php_eol;}
2013-12-01 23:42 from Dongguan, Sha Tin Branch to the Dongguan company
2013-12-02 00:35 Express has arrived in Dongguan company scanner is Li Yuewen on a stop is a branch of Dongguan Shatin
2013-12-02 01:35 sent by Dongguan company to Chengdu Distribution Center
2013-12-03 18:41 Express has arrived in Chengdu Distribution center scanner is Li Han soldiers on a stop is Dongguan company
2013-12-03 20:27 sent by Chengdu Distribution Center to Dazhou (0818-2660770)
2013-12-04 12:58 Shipment has arrived Dazhou (0818-2660770) the scanner is 81800. Previous station is Chengdu Distribution Center
2013-12-04 13:24 sent by Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
2013-12-04 16:32 Shipment has arrived Dazhu (0818-6259812,15908382116) scanner is 81801 previous stop is Dazhou (0818-2660770)
2013-12-04 16:32 0818-6259812,15908382116 's dispatch officer, number 88th, is sending a piece.
2013-12-04 16:33 Zhu (0818-6259812,15908382116) is in the shipment keeping position scanning
2013-12-06 12:43 has signed, the sign is my

Header (' content-type:text/html;charset=utf-8 '); $s =<<< XML
  
 
  
   
    3
   
  
  
   
  
  
   
    0
   
  
  
   
     
     2013-12-01 23:42 
     
       from Dongguan Shatin Branch to Dongguan company
      
 
 

    
   
   
     
     2013-12-02 00:35 
     
       Express has arrived in Dongguan company scanner is Li Yuewen on a station is a branch in Shatin, Dongguan
      
 
 

    
   
   
     
     2013-12-02 01:35 was
     
       sent to Chengdu Distribution Center by Dongguan company
      
 
 

    
   
   
     
     2013-12-03 18:41 
     
       Express has arrived in Chengdu Distribution center scanner is Li Han soldiers on a stop is Dongguan company
      
 
 

    
   
   
     
     2013-12-03 20:27 
     
       from Chengdu Distribution Center sent to Dazhou (0818-2660770)
      
 
 

    
   
   
     
     2013-12-04 12:58 
     
       Express has arrived Dazhou (0818-2660770) The scanner is 81800 the previous station is Chengdu Distribution Center
      
 
 

    
   
   
     
     2013-12-04 13:24 
     
       from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
      
 
 

    
   
   
     
     2013-12-04 16:32 
     
       Express has reached Dazhu (0818-6259812,15908382116) scanner is 81801 previous stop is Dazhou (0818-2660770)
      
 
 

    
   
   
     
     2013-12-04 16:32 
     
       (0818-6259812,15908382116), dispatch, 88th, is sending a piece.
      
 
 

    
   
   
     
     2013-12-04 16:33 da Zhu
     
       (0818-6259812,15908382116) is in the shipment keeping position scanning
      
 
 

    
   
   
     
     2013-12-06 12:43 
     
       has signed, the sign is my
      
 
 

    
   
  
   
    580038002019
   
  
  
   
    Daily Express
   
  
  
   
    Tiantian
   
  
  
   
    1386399373
   
  
  
   
    4373
   
  
  
   
    ASC
   
  
 XML, $xml = simplexml_load_string ($s), foreach ($xml->xpath ('//item ') as $item) {echo $item->time, ', $item->co ntext, Php_eol;}
2013-12-01 23:42 from Dongguan, Sha Tin Branch to the Dongguan company
2013-12-02 00:35 Express has arrived in Dongguan company scanner is Li Yuewen on a stop is a branch of Dongguan Shatin
2013-12-02 01:35 sent by Dongguan company to Chengdu Distribution Center
2013-12-03 18:41 Express has arrived in Chengdu Distribution center scanner is Li Han soldiers on a stop is Dongguan company
2013-12-03 20:27 sent by Chengdu Distribution Center to Dazhou (0818-2660770)
2013-12-04 12:58 Shipment has arrived Dazhou (0818-2660770) the scanner is 81800. Previous station is Chengdu Distribution Center
2013-12-04 13:24 sent by Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
2013-12-04 16:32 Shipment has arrived Dazhu (0818-6259812,15908382116) scanner is 81801 previous stop is Dazhou (0818-2660770)
2013-12-04 16:32 0818-6259812,15908382116 's dispatch officer, number 88th, is sending a piece.
2013-12-04 16:33 Zhu (0818-6259812,15908382116) is in the shipment keeping position scanning
2013-12-06 12:43 has signed, the sign is my


My XML above is a link within the content, how can I get the link within the XML, and do the processing?

Simplexml_load_file (file name)
Simplexml_load_string (file_get_contents (filename))

The key is to get a plain XML document that cannot contain anything else
Otherwise, treat it as a string.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.