Xpath Tutorial - How To Choose Elements Inwards Xpath Based On Attribute Together With Chemical Component Subdivision Value Example

In this XPATH tutorial nosotros volition encounter event of selecting elements based upon its value or attribute value. We volition encounter how to guide betwixt 2 elements based upon value of its youngster elements or based upon value of its attribute. XPATH is an of import concept to sympathise if you lot are working amongst XML files. Most of Back-office platform relies on XML files for transporting information from i arrangement to other as well as if you lot are working on whatever back-office or middle business office arrangement inward Java or .NET, its of import to know close XPATH as well as survive able to job XPATH to guide information from XML. Some fourth dimension dorsum I accept shared my XPATH notes for Java programmer as well as this event shows truthful ability of XPATH equally how convenient its to made selective decision. For those who are completely novel inward XML as well as XPATH, XPATH is cracking xml tool which allows you lot to question XML document as well as guide or remember selective information much similar SQL but if you lot are novel to XPATH or haven't had much sense amongst XML tool as well as technology than you lot volition combat to abide by right syntax of XPATH for your unlike need.


XPATH to guide chemical component subdivision based on attribute as well as value

Here is our sample xml, which nosotros volition job inward this XPATH tutorial :


<orders>
        <order orderNumber="1">
                <item>Electronics</item>
                <total>100</total>
        </order>
        <order orderNumber="2">
                <item>Computers</item>
                <total>200</total>
        </order>
        <order orderNumber="3">
                <item>food</item>
                <total>300</total>
        </order>
</orders>

In this XPATH tutorial nosotros volition encounter event of selecting elements based upon its value or a XPath Tutorial - How to guide elements inward XPATH based on attribute as well as chemical component subdivision value example
In kickoff event of XPATH human face nosotros volition encounter how to guide full chemical component subdivision for lodge which has especial value "Electronics"

XPATH :
/orders/order[item/text()='Electronics']/total
value : 100

here text() business office returns value of <item> element
[] brackets are used to define status or predicate, which is comparison text of <item> tag amongst “Electronics”. Similarly nosotros tin extend this XPATH to abide by full for Orders where especial is Computers as well as food

/orders/order[item/text()='Computers']/total
200

/orders/order[item/text()='food']/total
300

On instant event of XPATH human face nosotros volition abide by full chemical component subdivision for lodge whose orderNumber attribute has value "2"

XPATH : /orders/order[@orderNumber='1']/total
value : 100

here [] is used for status as well as @ is used to teach value from attribute.

/orders/order[@orderNumber='2']/total
200

/orders/order[@orderNumber='3']/total
300

If you lot are novel to XML or XPATH I propose using XML-SPY tool it has inward built XPATH evaluator which shows the termination of XPATH equally shortly equally you lot type as well as it supports XPath1.0 as well as XPATH2.0 equally beta. It also has XPATH re-create functionality as well as hence you lot tin merely guide whatever chemical component subdivision inward XML inward its grid sentiment as well as re-create its XPATH to job inward your Java program.

Further Learning
Java In-Depth: Become a Complete Java Engineer!
Master Java Web Services as well as REST API amongst Spring Boot
Difference betwixt DOM as well as SAX parser inward Java

Komentar

Postingan populer dari blog ini

Virtualbox - /Sbin/Mount.Vboxsf: Mounting Failed Amongst The Error: Protocol Fault [Solution]

Top Ten Jdbc Interview Questions Answers For Coffee Programmer

Fix Protocol As Well As Cause Messaging Interview Questions