Php parses Xml documents

Source: Internet
Author: User
Php parses Xml documents
3

0



Sent to Dongguan company by Shatian branch of Dongguan



The Courier has arrived at the Dongguan company. The scanner is Li Yuwen, the first station is DongGuan Shatian branch.

<
Time>
From Dongguan company to Chengdu distribution center



The Courier has arrived at the Chengdu distributed distribution center. the scanner is Li Hanbing. The Last Station is Dongguan.

Distributed from Chengdu to Dazhou (0818-2660770)



Express has arrived in Dazhou (0818-2660770). The scanner is 81800. The Last Station is the Chengdu distribution center.



Sent from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)

The parcel has arrived in Dazhu (0818-6259812,15908382116). The scanner is 81801. The Last Station is Dazhou (0818-2660770)



Dazhu (0818-6259812,15908382116) dispatched by dispatcher No. 88



Dazhu (0818-6259812,15908382116) is scanning the inventory



Accepted. the recipient is me.



580038002019
Daily Express Delivery
Tiantian
1386399373
4373
ASC


XML format. you want to output the content in the item cyclically!


Reply to discussion (solution)

Header ('content-type: text/html; charset = utf-8 '); $ s = <XML
  
 
  
   
3
  
  
  
   
0
  
  
   
    
    
     
Sent to Dongguan company by Shatian branch of Dongguan
    
   
   
    
    
     
The Courier has arrived at the Dongguan company. The scanner is Li Yuwen, the first station is DongGuan Shatian branch.
    
   
   
    
    
     
From Dongguan company to Chengdu distribution center
    
   
   
    
    
     
The Courier has arrived at the Chengdu distributed distribution center. the scanner is Li Hanbing. The Last Station is Dongguan.
    
   
   
    
    
     
Distributed from Chengdu to Dazhou (0818-2660770)
    
   
   
    
    
     
Express has arrived in Dazhou (0818-2660770). The scanner is 81800. The Last Station is the Chengdu distribution center.
    
   
   
    
    
     
Sent from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
    
   
   
    
    
     
The parcel has arrived in Dazhu (0818-6259812,15908382116). The scanner is 81801. The Last Station is Dazhou (0818-2660770)
    
   
   
    
    
     
Dazhu (0818-6259812,15908382116) dispatched by dispatcher No. 88
    
   
   
    
    
     
Dazhu (0818-6259812,15908382116) is scanning the inventory
    
   
   
    
    
     
Accepted. the recipient is me.
    
   
  
   
580038002019
  
  
   
Daily Express Delivery
  
  
   
Tiantian
  
  
   
1386399373
  
  
   
4373
  
  
   
ASC
  
 XML; $ xml = simplexml_load_string ($ s); foreach ($ xml-> xpath ('// item') as $ item) {echo $ item-> time ,'', $ item-> context, PHP_EOL ;}
Am sent to the Dongguan company by the Sha Tin division of Dongguan
Express has arrived at Dongguan company scanner is Li Yuewen previous station is DongGuan Shatian one branch
Was sent from Dongguan to Chengdu distribution center
At, the courier arrived at the Chengdu distribution center. the scanner was Li Hanbing, a Dongguan company.
Was sent to Dazhou by Chengdu distribution center (0818-2660770)
Express has arrived in Dazhou (0818-2660770). The scanner is 81800. the previous station is the Chengdu distribution center.
Was sent from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
Express has arrived in Dazhu (0818-6259812,15908382116). The scanner is 81801. the scanner is Dazhou (0818-2660770) on the previous station)
The dispatcher of Dazhu (0818-6259812,15908382116) is dispatching
Dazhu (0818-6259812,15908382116) is scanning warehouse holding
At, I signed for it.

Header ('content-type: text/html; charset = utf-8 '); $ s = <XML
  
 
  
   
3
  
  
  
   
0
  
  
   
    
    
     
Sent to Dongguan company by Shatian branch of Dongguan
    
   
   
    
    
     
The Courier has arrived at the Dongguan company. The scanner is Li Yuwen, the first station is DongGuan Shatian branch.
    
   
   
    
    
     
From Dongguan company to Chengdu distribution center
    
   
   
    
    
     
The Courier has arrived at the Chengdu distributed distribution center. the scanner is Li Hanbing. The Last Station is Dongguan.
    
   
   
    
    
     
Distributed from Chengdu to Dazhou (0818-2660770)
    
   
   
    
    
     
Parcels have arrived in Dazhou (0818-2660770). The scanner is 81800. The Last Station is the Chengdu distribution center.
    
   
   
    
    
     
Sent from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
    
   
   
    
    
     
The parcel has arrived in Dazhu (0818-6259812,15908382116). The scanner is 81801. The Last Station is Dazhou (0818-2660770)
    
   
   
    
    
     
Dazhu (0818-6259812,15908382116) dispatched by dispatcher No. 88
    
   
   
    
    
     
Dazhu (0818-6259812,1515908382116) is scanning the warehouse holding of parcels
    
   
   
    
    
     
Accepted. the recipient is me.
    
   
  
   
580038002019
  
  
   
Daily Express Delivery
  
  
   
Tiantian
  
  
   
1386399373
  
  
   
4373
  
  
   
ASC
  
 XML; $ xml = simplexml_load_string ($ s); foreach ($ xml-> xpath ('// item') as $ item) {echo $ item-> time ,'', $ item-> context, PHP_EOL ;}
Am sent to the Dongguan company by the Sha Tin division of Dongguan
Express has arrived at Dongguan company scanner is Li Yuewen previous station is DongGuan Shatian one branch
Was sent from Dongguan to Chengdu distribution center
At, the courier arrived at the Chengdu distribution center. the scanner was Li Hanbing, a Dongguan company.
Was sent to Dazhou by Chengdu distribution center (0818-2660770)
Express has arrived in Dazhou (0818-2660770). The scanner is 81800. the previous station is the Chengdu distribution center.
Was sent from Dazhou (0818-2660770) to Dazhu (0818-6259812,15908382116)
Express has arrived in Dazhu (0818-6259812,15908382116). The scanner is 81801. the scanner is Dazhou (0818-2660770) on the previous station)
The dispatcher of Dazhu (0818-6259812,15908382116) is dispatching
Dazhu (0818-6259812,15908382116) is scanning warehouse holding
At, I signed for it.


The xml above is the content in a link. how can I retrieve and process the xml in the link?

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

The key is that the obtained file must be a pure xml document and cannot contain any other content.
Otherwise, it should be processed 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.