How To Get Value type = 'Microsoft Lumia'. This is output:
<phone>
<model type="Microsoft Lumia">
<lumia id="Lumia 650">
<displaySize>4 Inch</displaySize>
<platformOS>Windows</platformOS>
</lumia>
<lumia id="Lumia 890">
<displaySize>5 Inch</displaySize>
<platformOS>Windows</platformOS>
</lumia>
this is my syntax:
$roottag = $dom->getElementsByTagName("model")[0].getAttribute("type[contain='Microsoft Lumia']");
can somebody help me ! thanks in advance
You haven't tagged the question with a programming language, but your code looks very much like PHP using the DOM extension:
If I understand you correctly, the problem is that you don't know how to fetch a
modelelement havingtypeattribute with a value containing'Microsoft Lumia'string. This is easily done with the following XPath expression:The double slash selects all
modelelements in the document. The condition in square brackets filters out the result set by the test callingcontainsfunction. The function checks if thetypeattribute value contains the given keyword.Fortunately, the DOM extension supports XPath through its
DOMXPathclass. If your code is not PHP, you still can figure out the solution in your language. The general idea is to use XPath as shown above.Example in PHP
The following example prints the
typeattribute values containingLumiakeyword.Output