<ApplicationMenu> <Menultem name’File’> Menuftem name=’New> <Menultem nameI?

You use Microsoft Visual Studio 2010 and Microsoft NET Framework 4 to create an application. The
application contains the following XML fragment.
<ApplicationMenu>
<Menultem name’File’>
Menuftem name=’New>
<Menultem nameI?rojectw I>
<Menultem name’Web Site’ I> <4Aenultem>
<Menultem name=’Open> <Menultem name=Project”>
<Menultem name’Web Site”>
<iNenultem> <Menultem narner”Save0 1>
</1ienuttem>
<Menultem nameEdr>
<Menultem nameCut” I>

<Menultem name”C0W I>
<Menultem name’Paste01>
<‘Menultem>
<Menultem name’1-4elp’>
<Menultem namezlHeIp I>
<Menultem name”About’ I>
</Menulteni>
</ApplicationMenu’
The application queries the XML fragment by using the Xml Document class. You need to select all
the descendant elements of the Menultem element that has its name attribute as File Which XPath
expression should you use?

You use Microsoft Visual Studio 2010 and Microsoft NET Framework 4 to create an application. The
application contains the following XML fragment.
<ApplicationMenu>
<Menultem name’File’>
Menuftem name=’New>
<Menultem nameI?rojectw I>
<Menultem name’Web Site’ I> <4Aenultem>
<Menultem name=’Open> <Menultem name=Project”>
<Menultem name’Web Site”>
<iNenultem> <Menultem narner”Save0 1>
</1ienuttem>
<Menultem nameEdr>
<Menultem nameCut” I>

<Menultem name”C0W I>
<Menultem name’Paste01>
<‘Menultem>
<Menultem name’1-4elp’>
<Menultem namezlHeIp I>
<Menultem name”About’ I>
</Menulteni>
</ApplicationMenu’
The application queries the XML fragment by using the Xml Document class. You need to select all
the descendant elements of the Menultem element that has its name attribute as File Which XPath
expression should you use?

A.
//[@name=’File’][name( )‘Menultem’]

B.
/ApplicationMenu/Menultem[FiI&)f(Menultem

C.
/ApphcationMenulMenultem/descendant: :Menultem[file’]

D.
/ApplicationMenu/Menultem[name=File’]/descendant. Menultem

Explanation:
XPath Examples:
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem[@name=’File’]/descendant::
MenuItem”); // 01 == 02
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem[@name=’File’]//MenuItem”);
// 02 ==
01
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem[2]/descendant::MenuItem”);
// 03
XmlNodeList nodes =
doc.SelectNodes(“/ApplicationMenu/MenuItem[last()]/descendant::MenuItem”); // 04
XmlNodeList nodes =
doc.SelectNodes(“/ApplicationMenu/MenuItem/descendant::MenuItem[/ApplicationMenu/
MenuItem/@name=@name]”); // 05
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem/*”); // 06
XmlNodeList nodes =
doc.SelectNodes(“/ApplicationMenu/MenuItem/descendant::*[@Description]”); //07
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem[MenuItem][position()=2]”); //
08 == 09
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem[MenuItem and
position()=2]”); // 09 == 08
XmlNodeList nodes = doc.SelectNodes(“/ApplicationMenu/MenuItem[SubMenu or position()=2]”); //
10
XPath Examples
(http://msdn.microsoft.com/en-us/library/ms256086.aspx)



Leave a Reply 0

Your email address will not be published. Required fields are marked *