473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Parsing XML for a specific text node (someone who knows DOM, plz help)

I have this XML here:

<?xml version="1.0"?>
<scopes>
<item>
<scope>scope1</scope>
<description>description of the scope</description>
<scopeID>12vkjlasc</scopeID>
</item>
<item>
<scope>scope2</scope>
<description>description of the scope2</description>
<scopeID>8s9sm2emk</scopeID>
</item>
<item>
<scope>scope3</scope>
<description>description of the scope3</description>
<scopeID>7tqsxjnds</scopeID>
</item>
</scopes>


now i want to have the item with a specific scopeID as my output, what i mean is, if lets say i know a scopeID, assume it to be '12vkjlasc', then i get the output from my above XML as :

<item>
<scope>scope1</scope>
<description>description of the scope</description>
<scopeID>12vkjlasc</scopeID>
</item>

or even this would work:

<scope>scope1</scope>
<description>description of the scope</description>
<scopeID>12vkjlasc</scopeID>


Any ideas? Thx in advance!
Jun 12 '07 #1
2 1196
r035198x
13,262 8TB
I have this XML here:

<?xml version="1.0"?>
<scopes>
<item>
<scope>scope1</scope>
<description>description of the scope</description>
<scopeID>12vkjlasc</scopeID>
</item>
<item>
<scope>scope2</scope>
<description>description of the scope2</description>
<scopeID>8s9sm2emk</scopeID>
</item>
<item>
<scope>scope3</scope>
<description>description of the scope3</description>
<scopeID>7tqsxjnds</scopeID>
</item>
</scopes>


now i want to have the item with a specific scopeID as my output, what i mean is, if lets say i know a scopeID, assume it to be '12vkjlasc', then i get the output from my above XML as :

<item>
<scope>scope1</scope>
<description>description of the scope</description>
<scopeID>12vkjlasc</scopeID>
</item>

or even this would work:

<scope>scope1</scope>
<description>description of the scope</description>
<scopeID>12vkjlasc</scopeID>


Any ideas? Thx in advance!
Are you able to read the XML file using JAXP?
Jun 12 '07 #2
Are you able to read the XML file using JAXP?
yup, i'm able to read the XML ... for eg. i can get the root name using this code:

File file = new File(filePath);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element " + doc.getDocumentElement().getNodeName());
Jun 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Anders Eriksson | last post by:
Hello! I want to extract some info from a some specific HTML pages, Microsofts International Word list (e.g. http://msdn.microsoft.com/library/en-us/dnwue/html/swe_word_list.htm). I want to...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
6
by: Grant | last post by:
I have this simple xml file which wont ever get beyong 3 nodes deep. I need to get the value of the child node of any node with an id of '63'. So fir instance I would be returned 'False' from the...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
9
by: B | last post by:
I have an XML string <?xml version="1.0" encoding="UTF-8"?> <SSOUser><Status>FAIL</Status><Message>Unable to find session id of 1137018716939</Message></SSOUser> That I am trying to...
0
by: XML newbie: Urgent pls help! | last post by:
I am using Vb.net. I am new to XML.I appreciate your help in advance. Please reply soon. When I try to parse: I get the following error message: Unable to cast COM object of type...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
2
by: hzgt9b | last post by:
I've written a simple javascript page that parses an XML file... (Actually I just modified the "Parsing an XML File" sample from http://www.w3schools.com/dom/dom_parser.asp) The page works great...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.