How to select two different elements with an XPath query

Tags: php,xpath,css-selectors

Problem :

I select <a id="categoryBrandIcon"> with:

$item = $xpath->query("//a[@id='categoryBrandIcon']")->item(0);

How do I modify the code to select <a id="categoryBrandIcon"> and all <input type="hidden"> tags?

Selecting inputs if input[@type='hidden'] but I don't know how to chain those two.

With CSS selectors I would do this a#categoryBrandIcon, input[type="hidden"]

Solution :

Yes you could combine them in a single xpath query thru pipe. Example:

$sample_markup = '
<div class="container">
    <a id="categoryBrandIcon" href="#">Test</a>
    <input type="hidden" />
    <input type="text" />

$dom = new DOMDocument();
$xpath = new DOMXPath($dom);

$elements = $xpath->query("//a[@id='categoryBrandIcon'] | //input[@type='hidden']");
foreach($elements as $e) {
    // loop thru found elements

    CSS Howto..

    How to load a small css background image before lots of other images (html element in .css file)?

    How do I apply css code for svg in google api charts

    How can I make this menu using only anchor tag and css Not using ul and li?

    How can I move text to the left with CSS?

    How to get conditional css to work on Blogger/Blogspot?

    How make contents as a grid in a ScrollPanel in GWT project using UIBinder

    How to vertically align div text?

    Navigation Menu That Shows/Hides On Rollover and Click

    Show div at mouse click position, accounting for scrolling

    how to get the cssText of external style?

    How to override background image defined in CSS with another CSS?

    How to remove CSS attribute such that HTML attribute will take effect again?

    how to bring two blocks closer

    How to handle an id tag with '.' in CSS

    How do I fix my css floats on IE 6 & 7? Or how can I lay this out better?

    How To Create Full Screen Fixed With Scrolling Background Images

    How to reference JSF image resource as CSS background image url

    How to change CSS with jQuery change and this

    How can I line up the two containers in view?

    How to inherit CSS Menu on each html page linked on Homepage without using any javascript and templates

    How to get jquery ui tabs working?

    how to get double border in using CSS?

    How to blur one side of the div using CSS

    Use ajax to show-hide only a subset of image

    How to.. the middle div of three ever on center and if the navigator are resized

    I can not load the CSS pages which can be accessed after a login carry with spring security. How can I fix it?

    How to use animation with transform CSS

    How to change scrollbar in textarea input?

    How to fit a div container to cover all the remaining space in between?

    How to keep the entire website aligned to the top when zooming-out using CSS (Firefox)?