Hey there! any question in your mind? Ask It Now!.

Popular Categories





How to get node or node value from HTML DOM(Document Object Model).

+1 vote
134 views
asked in Programming by nishant (380 points)

I am new in DOM and want to collect a particular node value of a div my environment is in PHP.

I am trying to get node values from DOM but not getting success, I hope any one of you help me out Thanks!

1 Answer

+1 vote
answered by duke Expert (5,813 points)
edited by Bhartesh
 
Best answer

DOM is a interface for the programming languages like HTML, XHTML and XML, Here we are talikg about HTML so in HTML DOM there is a node which contains some values which is called node values lets see a example :

Say we have a url : $domain = www.xyz.com

 

$doc = new DOMDocument();

// Get the sourcecode of the domain

@$doc->loadHTMLFile($domain);

 

//here we are collecting all div tags from web page

$div = $doc->getElementsByTagName('div');

 

foreach($books as $div)

{

 

$class = $div->getAttribute('class');

if (strpos($class, 'price') !== false)

{

 

echo $class->nodeValue;

 

}

}




In this example we are using PHP and printing all node values of class price.

commented by nishant (380 points)
thanks for such a nice explanation.

Related Questions

+1 vote
2 answers 4,756 views
+1 vote
1 answer 729 views
+1 vote
2 answers 72 views
+4 votes
1 answer 139 views
+2 votes
1 answer 138 views
+5 votes
1 answer 55 views
+6 votes
2 answers 2,021 views

Not a Member yet?

Ask to Folks Login

My Account
154 Folks are online
0 members and 154 guest online
Your feedback is highly appreciated