Let us say I have an xml tag like:
<test val="val1 ">Test XML</test>
I want to parse the value “val1” whenever <test> tag occurs in the file so that I can save it to an array.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can load the XML from the file and select all elements with tag name
testand extract attribute value from it.Basically:
doc.getElementsByTagName("test")in order to select all"test"elements, and for each element found you can select its attribute named"val"withnode.getAttributes().getNamedItem("val")and from this one, if not null justgetTextContent()to take its text content.A sample code could be something like:
This will print: