Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
XML and Related Technologies
how to get specific root, element and node?
Wayne Wong Qi Yuan
Greenhorn
Posts: 4
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
<company> <getSource> <fullname>wong</fullname> <family> <brothername>aini</brothername> </family> </getSource> <setSource> <fullname>Qi</fullname> <family> <brothername>aita</brothername> </family> </setSource> </company>
i been research quite a long time...
i cant figure out how to show this part that i want
<getSource> <fullname>wong</fullname> <family> <brothername>aini</brothername> </family> </getSource>
please kindly help
D. Ogranos
Ranch Hand
Posts: 214
posted 12 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
For parsing the XML, check out the API documentation for
org.w3c.dom.Document
javax.xml.parsers.DocumentBuilder
javax.xml.parsers.DocumentBuilderFactory
Then use XPath to find specific nodes in the document. See
javax.xml.xpath.XPathExpression
javax.xml.xpath.XPath
javax.xml.xpath.XPathFactory
If you have problems with any part, post again
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Harold's free on-line book
is loaded with examples. A bit old but still perfectly usable.
Bill
Wayne Wong Qi Yuan
Greenhorn
Posts: 4
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thank to Second Post...
is help a lot....
i can get the node that i want in xml
using xpath can get any node from different lvl of root....
share what i done
public class XPathAttribute { public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse("src/a.xml"); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("//g/f/*/text()"); Object result = expr.evaluate(doc, XPathConstants.NODESET); //for loop for expr NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { System.out.println(nodes.item(i).getNodeValue()); } } }
Just the other day, I was thinking ... about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Can�t set managed bean property�.
How can I set bean property in JSF page?!
square bracket in send mail
Getting the class name without the full package
Regex for Reversing Last Name, First Name?
More...