PDA

View Full Version : how to export ''Keywords" , "Description" tag in HTML file using LIbXml?




saleh.hi.62
Dec 7, 2011, 08:38 AM
hello guys,

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

i tried this:

/html/head/meta/keywords

it's not correct ! how can i do it correctly?



MasConejos
Dec 7, 2011, 02:03 PM
For keywords, assuming you want the text in the content attribute:
/html/head/meta[@name="keywords"]/@content

For description:
/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

jiminaus
Dec 7, 2011, 08:08 PM
Let me reiterate. Go through the XPath tutorial here. http://www.w3schools.com/xpath/. You can't just stab in the dark and expect to get very far.

saleh.hi.62
Dec 7, 2011, 08:54 PM
For keywords, assuming you want the text in the content attribute:
/html/head/meta[@name="keywords"]/@content

For description:
/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
Dec 8, 2011, 12:37 AM
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
Dec 8, 2011, 06:36 AM
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.