Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1411365 DB Design and Implementation inventory.xml <?xml version=\"1.0\"?> <?xml

ID: 3677757 • Letter: 1

Question

1411365 DB Design and Implementation

inventory.xml

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="myfile.xsl" ?>

<bookstore specialty="novel">

<book>

    <author>

      <first-name>Joe</first-name>

      <last-name>Bob</last-name>

      <award>Trenton Literary Review Honorable Mention</award>

    </author>

    <price>12</price>

</book>

<book>

    <author>

      <first-name>Mary</first-name>

      <last-name>Bob</last-name>

      <publication>Selected Short Stories</publication>

    </author>

    <editor>

      <first-name>Britney</first-name>

      <last-name>Bob</last-name>

    </editor>

    <price>55</price>

</book>

<magazine frequency="monthly">

    <price>2.50</price>

    <subscription price="24" per="year"/>

</magazine>

<book id="myfave">

    <author>

      <first-name>Toni</first-name>

      <last-name>Bob</last-name>

      <degree from="Trenton U">B.A.</degree>

      <degree from="Harvard">Ph.D.</degree>

      <award>Pulitzer</award>

      <publication>Still in Trenton</publication>

      <publication>Trenton Forever</publication>

    </author>

    <price intl="Canada" exchange="0.7">6.50</price>

    <excerpt>

      <p>It was a dark and stormy night.</p>

      <p>But then all nights in Trenton seem dark and

      stormy to someone who has gone through what

      <emph>I</emph> have.</p>

      <definition-list>

        <term>Trenton</term>

        <definition>misery</definition>

      </definition-list>

    </excerpt>

</book>

<my:book xmlns:my="uri:mynamespace" price="29.50">

    <my:title>Who's Who in Trenton</my:title>

    <my:author>Robert Bob</my:author>

</my:book>

</bookstore>

Explanation / Answer

Write the following xpath queries for inventory.xml
Just i explain with php code

//first we create DOM object
$html_dom = new DOMDocument();
//now we load xml file
@$html_dom->loadHTML($html);

$x_path = new DOMXPath($html_dom);
//now we set xpath in query
$nodes= $x_path->query("//editor");
// finaly we run for loop and get result
foreach ($nodes as $node)
{
// put your code here
}

Following Xpath queries according to question.
Add and run xpath queries


a) //editor

we get all editor elements by //editor. xpath="//editor";

b) //book[3]/author

we get author's elements of third book elements by //book[3]/author. xpath="//book[3]/author";
in this //book[3] see third book element in xml and get author's according to book element

c) //bookstore/book[@style='textbook']
we get author's elements of third book elements by //bookstore/book[@style='textbook']. xpath="//bookstore/book[@style='textbook']";
in this first check bookstore element then see book with


d) //book[.//award]
we get award elements belong to book element by //book[.//award]. xpath="//book[.//award]";

e) bookstore//title
we get all title element in in xml. first we use bookstore because over root element is bookstore then search title by //title. xpath="bookstore//title";

f) //magazine/price
you also try with this
bookstore/magazine//price

we get price element in magazine element by //magazine/price. xpath="//magazine/price";

g) //bookstore/book[price>50]/author
you also try wuht this
//bookstore/book[price>50]//author

we get all author where price is greater then 50 by //bookstore/book[price>50]/author. xpath="//bookstore/book[price>50]/author";

h) //book[@style]

we get all element wuth style attributes by //book[@style]. xpath="//magazine/price";

for online testing you use this link.
Stap 1 :- add xml file in xml input box or url
Stap 2 :- second XPath expression
Stap 3 :- click on test xpath

Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote