Mac how to export ''Keywords" , "Description" tag in HTML file using LIbXml?

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
hello guys,

how to export ''Keywords" , "Description" tag in HTML file using LIbXml?

i tried this:

Code:
/html/head/meta/keywords
it's not correct ! how can i do it correctly?
 

MasConejos

macrumors regular
Jun 25, 2007
149
43
Houston, TX
For keywords, assuming you want the text in the content attribute:
Code:
/html/head/meta[@name="keywords"]/@content
For description:
Code:
/html/head/meta[@name="description"]/@content
Keep in mind that the html you are trying to parse/query needs to be xml compliant. Also be aware that xml is case sensitive, so if the html document uses a different case (i.e. <META/> or <meta name="KEYWORDS"/>, etc). then this xpath expression wont work.

You may be better off using DOM or regular expressions, depending on what you want
 

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
For keywords, assuming you want the text in the content attribute:
Code:
/html/head/meta[@name="keywords"]/@content
For description:
Code:
/html/head/meta[@name="description"]/@content
Keep in mind that the html you are trying to parse/query needs to be xml compliant. Also be aware that xml is case sensitive, so if the html document uses a different case (i.e. <META/> or <meta name="KEYWORDS"/>, etc). then this xpath expression wont work.

You may be better off using DOM or regular expressions, depending on what you want
thank you so much, i have read that tutorial, but its not something very practical and illuminated. !
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
i have read that tutorial, but its not something very practical and illuminated. !
So this example of the tutorial wasn't illuminating?
//title[@lang='eng']

Selects all the title elements that have an attribute named lang with a value of 'eng'
You didn't go "Well that's pretty much what I want except I want meta elements that have an attribute named name with a value of description. The forumula seems to be //element[@attribute='value'], perhaps I'll give //meta[@name='description'] a go'. You really didn't run that thought?! Oh, wait, of course you didn't. I seem to have forgotten whose post it is I'm reply to.
 

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
So this example of the tutorial wasn't illuminating?


You didn't go "Well that's pretty much what I want except I want meta elements that have an attribute named name with a value of description. The forumula seems to be //element[@attribute='value'], perhaps I'll give //meta[@name='description'] a go'. You really didn't run that thought?! Oh, wait, of course you didn't. I seem to have forgotten whose post it is I'm reply to.
yes you are right, i was not checking carefully.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.