XML Tutorial

DTD Tutorial

XPath Tutorial



XPath Attribute Expression For Finding XPath Node


XPath Attribute expression location path for finding XPath node in XML document. XPath give you control to create attribute expression for locating node in XML document.

XPath Attribute Expression For Finding XPath Node

Following are some XPath attribute expressions for locating XPath nodes.

Expression Description
@ Attribute selector identifier
@discipline select discipline attributes of the context.
//employee/@id Element attribute
Select employee elements with id attribute within XML document.
/empinfo/employee/@id Element attribute of the root element
Select employee elements with id attribute of the empinfo root element.
@* all attribute of the context node
//@* All attribute within XML document
//@id id attribute within XML document

@discipline : Select discipline attributes of the context.

Expression relation : Attribute selector identifier

XPath selection : select all attribute value in highlighted lines.

@discipline

<?xml version="1.0" standalone="yes"?>
<empinfo>
	<employee id="1">
		<name>Opal Kole</name>
		<designation discipline="web" experience="3 year">Senior Engineer</designation>
		<email>OpalKole@myemail.com</email>
	</employee>
	<employee id="2">
		<name from="CA">Max Miller</name>
		<designation discipline="DBA" experience="2 year">DBA Engineer</designation>
		<email>maxmiller@email.com</email>
	</employee>
	<employee id="3">
		<name>Beccaa Moss</name>
		<designation discipline="appdev">Application Developer</designation>
		<email>beccaamoss@email.com</email>
	</employee>
</empinfo>

//employee/@id : Select employee elements with id attribute within XML document.

Expression relation : Element attribute

XPath selection : id attribute value (3, 8, 13 lines).

//employee/@id

<?xml version="1.0" standalone="yes"?>
<empinfo>
	<employee id="1">
		<name>Opal Kole</name>
		<designation discipline="web" experience="3 year">Senior Engineer</designation>
		<email>OpalKole@myemail.com</email>
	</employee>
	<employee id="2">
		<name from="CA">Max Miller</name>
		<designation discipline="DBA" experience="2 year">DBA Engineer</designation>
		<email>maxmiller@email.com</email>
	</employee>
	<employee id="3">
		<name>Beccaa Moss</name>
		<designation discipline="appdev">Application Developer</designation>
		<email>beccaamoss@email.com</email>
	</employee>
</empinfo>

/empinfo/employee/@id : Select employee elements with id attribute of the empinfo root element.

Expression relation : Element attribute of the root element

XPath selection : id attribute value (3, 8, 13 lines).

/empinfo/employee/@id

<?xml version="1.0" standalone="yes"?>
<empinfo>
	<employee id="1">
		<name>Opal Kole</name>
		<designation discipline="web" experience="3 year">Senior Engineer</designation>
		<email>OpalKole@myemail.com</email>
	</employee>
	<employee id="2">
		<name from="CA">Max Miller</name>
		<designation discipline="DBA" experience="2 year">DBA Engineer</designation>
		<email>maxmiller@email.com</email>
	</employee>
	<employee id="3">
		<name>Beccaa Moss</name>
		<designation discipline="appdev">Application Developer</designation>
		<email>beccaamoss@email.com</email>
	</employee>
</empinfo>

//@* : Select all attribute value in XML document.

Expression relation : All attribute of the context node

XPath selection : select all attribute value in highlighted lines.

//@*

<?xml version="1.0" standalone="yes"?>
<empinfo>
	<employee id="1">
		<name>Opal Kole</name>
		<designation discipline="web" experience="3 year">Senior Engineer</designation>
		<email>OpalKole@myemail.com</email>
	</employee>
	<employee id="2">
		<name from="CA">Max Miller</name>
		<designation discipline="DBA" experience="2 year">DBA Engineer</designation>
		<email>maxmiller@email.com</email>
	</employee>
	<employee id="3">
		<name>Beccaa Moss</name>
		<designation discipline="appdev">Application Developer</designation>
		<email>beccaamoss@email.com</email>
	</employee>
</empinfo>

//@id : Select all attribute value in XML document.

Expression relation : Anywhere attribute

XPath selection : id attribute value (3, 8, 13 lines).

//@id

<?xml version="1.0" standalone="yes"?>
<empinfo>
	<employee id="1">
		<name>Opal Kole</name>
		<designation discipline="web" experience="3 year">Senior Engineer</designation>
		<email>OpalKole@myemail.com</email>
	</employee>
	<employee id="2">
		<name from="CA">Max Miller</name>
		<designation discipline="DBA" experience="2 year">DBA Engineer</designation>
		<email>maxmiller@email.com</email>
	</employee>
	<employee id="3">
		<name>Beccaa Moss</name>
		<designation discipline="appdev">Application Developer</designation>
		<email>beccaamoss@email.com</email>
	</employee>
</empinfo>