473,399 Members | 4,177 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,399 software developers and data experts.

How to get value of XML "Element " type node

Hi,

I want to fetch some values from a XML file, using a java program.
I want to retrieve value of path tag for e.g<path>some path</path>
tag.(Marked with **** in the below XML file Example)

=============
My XML File
============

<maindata id="U00abfd8a-0ce7-ced5-00f6-00fff5bfdea9" host="e05k02"
addr="10.64.33.86" domain="BrioPortal 7.0 Development"
version="7.0.1.17" date="2003-08-04 14:20:23-07">
<Category name="MigSMACT" version="7.0.1.17"
id="U01929031-0e01-ced5-00f6-00fff5bfdea9">
<gendate>2003-08-04 14:20:25-07</gendate>
<cattribs>
<autodelete>false</autodelete>
<browsable>true</browsable>
<datecreated>2003-07-28&sp;14:35:33-07</datecreated>
<description>New&sp;Category</description>
<group name="ADMINISTRATOR"
idref="U0159c5ff-13e4-ced5-00f6-00fff5bfdea9"/>
<lastmodified>2003-07-28&sp;14:35:33-07</lastmodified>
<name>MigSMACT</name>
<objectid>HXLWIRBZFXECHBDYAGHLIRRPZe0Ck0N-BCRRP_Z0FK0N</objectid>
<objecttype mimetype="Category"
idref="U00d5f038-13e8-ced5-00f6-00fff5bfdea9"/>
<owner name="dw1portl"
idref="U0057d3f5-143b-ced5-00f6-00fff5bfdea9"/>
<parentcategory name="Migration Staging"
idref="U001c7c0d-1456-ced5-00f6-00fff5bfdea9"/>
<parentobjectid>FBRGZLXIDHCITIDYG0R0LLP_eZFkZC-FCLRB_E0FM0C</parentobjectid>
****** <path>/ABC&sp;Shipping/Goods&sp;Sale/Final</path> *******
<permissions>
<Permissions>
<groupexecutepermission>true</groupexecutepermission>
<groupreadpermission>true</groupreadpermission>
<groupwritepermission>true</groupwritepermission>
<ownerexecutepermission>true</ownerexecutepermission>
<ownerreadpermission>true</ownerreadpermission>
<ownerwritepermission>true</ownerwritepermission>
<worldexecutepermission>true</worldexecutepermission>
<worldreadpermission>true</worldreadpermission>
<worldwritepermission>true</worldwritepermission>
</Permissions>
</permissions>
</cattribs>
</Category>

==============
My Java Code
=============

DOMParser tParser = new DOMParser();
tParser.parse("WRTest_11-28-5:38_sdw-sb.xml");
Document doc = tParser.getDocument();

doc.getDocumentElement ();
System.out.println ("Root element :" +
doc.getDocumentElement().getNodeName());

NodeList objCatNodes = doc.getElementsByTagName("path");

int totalCatNodes = objCatNodes.getLength();
System.out.println("Total no of Path tags: " + totalCatNodes);

Node objNode=objCatNodes.item(0);
System.out.println("Path Name : " + objNode.getNodeName());

-------------------------------------
In the last System.out.println, it is returning NULL.

Please tell me what I need to do, to get the value. Plz help me its
Urgent. thanks in advance.

Amy..........
Jul 20 '05 #1
1 18712
The following will give you what you are looking for:
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;

public class amol {

public static void main(String[] args) {

try {
DOMParser tParser = new DOMParser();

tParser.parse(args[0]);
Document doc = tParser.getDocument();
doc.getDocumentElement();
System.out.println ("Root element :" +
doc.getDocumentElement().getNodeName());

NodeList objCatNodes = doc.getElementsByTagName("path");

int totalCatNodes = objCatNodes.getLength();
System.out.println("Total no of Path tags: " + totalCatNodes);

Node objNode=objCatNodes.item(0);

NodeList objNodes = objNode.getChildNodes();
System.out.println("Path Name : " + objNodes.item(0).getNodeValue());

} catch (Exception e) {e.printStackTrace();}
}

}

Enjoy!

- Finnbarr
am*****@indiatimes.com (Amol) wrote in message news:<fc**************************@posting.google. com>...
Hi,

I want to fetch some values from a XML file, using a java program.
I want to retrieve value of path tag for e.g<path>some path</path>
tag.(Marked with **** in the below XML file Example)

=============
My XML File
============

<maindata id="U00abfd8a-0ce7-ced5-00f6-00fff5bfdea9" host="e05k02"
addr="10.64.33.86" domain="BrioPortal 7.0 Development"
version="7.0.1.17" date="2003-08-04 14:20:23-07">
<Category name="MigSMACT" version="7.0.1.17"
id="U01929031-0e01-ced5-00f6-00fff5bfdea9">
<gendate>2003-08-04 14:20:25-07</gendate>
<cattribs>
<autodelete>false</autodelete>
<browsable>true</browsable>
<datecreated>2003-07-28&sp;14:35:33-07</datecreated>
<description>New&sp;Category</description>
<group name="ADMINISTRATOR"
idref="U0159c5ff-13e4-ced5-00f6-00fff5bfdea9"/>
<lastmodified>2003-07-28&sp;14:35:33-07</lastmodified>
<name>MigSMACT</name>
<objectid>HXLWIRBZFXECHBDYAGHLIRRPZe0Ck0N-BCRRP_Z0FK0N</objectid>
<objecttype mimetype="Category"
idref="U00d5f038-13e8-ced5-00f6-00fff5bfdea9"/>
<owner name="dw1portl"
idref="U0057d3f5-143b-ced5-00f6-00fff5bfdea9"/>
<parentcategory name="Migration Staging"
idref="U001c7c0d-1456-ced5-00f6-00fff5bfdea9"/>
<parentobjectid>FBRGZLXIDHCITIDYG0R0LLP_eZFkZC-FCLRB_E0FM0C</parentobjectid>
****** <path>/ABC&sp;Shipping/Goods&sp;Sale/Final</path> *******
<permissions>
<Permissions>
<groupexecutepermission>true</groupexecutepermission>
<groupreadpermission>true</groupreadpermission>
<groupwritepermission>true</groupwritepermission>
<ownerexecutepermission>true</ownerexecutepermission>
<ownerreadpermission>true</ownerreadpermission>
<ownerwritepermission>true</ownerwritepermission>
<worldexecutepermission>true</worldexecutepermission>
<worldreadpermission>true</worldreadpermission>
<worldwritepermission>true</worldwritepermission>
</Permissions>
</permissions>
</cattribs>
</Category>

==============
My Java Code
=============

DOMParser tParser = new DOMParser();
tParser.parse("WRTest_11-28-5:38_sdw-sb.xml");
Document doc = tParser.getDocument();

doc.getDocumentElement ();
System.out.println ("Root element :" +
doc.getDocumentElement().getNodeName());

NodeList objCatNodes = doc.getElementsByTagName("path");

int totalCatNodes = objCatNodes.getLength();
System.out.println("Total no of Path tags: " + totalCatNodes);

Node objNode=objCatNodes.item(0);
System.out.println("Path Name : " + objNode.getNodeName());

-------------------------------------
In the last System.out.println, it is returning NULL.

Please tell me what I need to do, to get the value. Plz help me its
Urgent. thanks in advance.

Amy..........

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Andrew | last post by:
It seems that in C#, given an instance "a" of some value type "A", one can pass a by reference to functions with signatures of either "void f(object obj)" or "void g(ref A obj)". But passing a into...
1
by: Paul Cheevers | last post by:
Hi, I've been trying to write some schema to validate the Value element of an Eq element but to no avail. If the Value Element is off type DateTime then the node should be able to contain text...
13
by: ahaupt | last post by:
Hi all, I'm implementing the Clone() method through the ICloneable interface and don't quite know how deep I need to go for a deep copy. Example: class A: ICloneable { object _val;
5
by: Dave | last post by:
I'd like to create a Registry key value where the Registry key value type is REG_QWORD. I'm using SetValue(name As String, value As Object), and I understand that the object type used in this...
10
by: John Bailo | last post by:
I want to pass a SqlCommand object as a input parameter to a method. I want to pass the SqlCommand "by value" so that any updates to the original object are *not* reflected in the object within...
4
by: Mathieu Cartoixa | last post by:
Hi, I have been annoyed in one of my recent projects with a problem related to the explicit implementation of an interface on a value type. I will take an example to show the problem. Say we...
3
by: Rich | last post by:
Another noob question for you all . . . I have functions written in C++ that I want to call from C#. I need to be able to pass a reference to a value type (like an int) so that the function can...
5
by: Diwa | last post by:
Does the "value" type (value as in key-value pair )of "std::map" require a default ctor even if it is not used ? If I comment out Line 1 in the code attached later, i.e remove the default ctor...
4
by: Smithers | last post by:
Are delegates value types or reference types? I was just pondering the fact that delegates are immutable... Does this mean that they are value types and not reference types? Thanks.
24
by: carnold | last post by:
Hello, I'm a developer coming from C++ and Java ... I've going thru "Effective C#" (which highly recommend for people coming from other languages wanting to learn C#), and it states that "value...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.