How can I quickly locate a DOMElement using DOMXpart?

Source: Internet
Author: User
Suppose there is such an xml, this can be not fixed {code ...} I first get an ID cut-off point through DOMDocument, as shown below: {code ...} excuse me, how can I quickly locate this cut point based on the DOMElement object, instead of getting it from the root directory Level 1 down, such as: {code ...} suppose there is such an xml file, which is not fixed.


      
           
                
     
      test.1            
      
       test.2
              
     
            
                
     
      test.3
                 
     
      test.4            
      
       test.5
              
     
        
       
   
    ...
   
  

I first get an ID cut point through DOMDocument, as shown below:

$ Dom = new DOMDocument; $ s1 = $ dom-> getElementByID ('s1'); // return a DOMElement object .. perform some column operations, for example, $ xpath = new \ DOMXpath; // obtain the cut-off point with the uv name attribute l1 under the ID cut-off point

Excuse me, how can IQuickly locate this cut point based on the DOMElement objectInstead of getting from the root directory Level 1, such:

(new DOMXpath)->query('/root/home/sea/uv[name=l1]');

Reply content:

Suppose there is such an xml file, which is not fixed.


      
           
                
     
      test.1            
      
       test.2
              
     
            
                
     
      test.3
                 
     
      test.4            
      
       test.5
              
     
        
       
   
    ...
   
  

I first get an ID cut point through DOMDocument, as shown below:

$ Dom = new DOMDocument; $ s1 = $ dom-> getElementByID ('s1'); // return a DOMElement object .. perform some column operations, for example, $ xpath = new \ DOMXpath; // obtain the cut-off point with the uv name attribute l1 under the ID cut-off point

Excuse me, how can IQuickly locate this cut point based on the DOMElement objectInstead of getting from the root directory Level 1, such:

(new DOMXpath)->query('/root/home/sea/uv[name=l1]');

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.