Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Get Data and Value of XML element in Java

Thread view: 
vunet.us@gmail.com - 19 Oct 2006 15:41 GMT
I am new to Java. I need to rewrite a function which gets XML elements
text as shown below to get elements value instead:

private String getCharacterDataFromElement(Element e){
 Node child = e.getFirstChild();
 if(child instanceof CharacterData){
   CharacterData cd = (Character) child;
   return cd.getData();
 }
return "?";
}

<xml>FUNCTION ABOVE GETS THIS<xml>

<xml value="NEED TO GET THIS VALUE"></xml>

THANKS TO ALL.
Oliver Wong - 19 Oct 2006 16:43 GMT
>I am new to Java. I need to rewrite a function which gets XML elements
> text as shown below to get elements value instead:
[quoted text clipped - 13 lines]
>
> THANKS TO ALL.

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/Element.html#getAttributes()

   - Oliver
vunet.us@gmail.com - 19 Oct 2006 16:56 GMT
Thank you Oliver, but I saw it many times. The problem is: I am new to
Java... I cannot understand how to use it.
Andrew, I will send you the code to your personal email... What is it?
Thanks.
Oliver Wong - 19 Oct 2006 17:25 GMT
> Thank you Oliver, but I saw it many times. The problem is: I am new to
> Java... I cannot understand how to use it.

   Then I recommend you learn Java. Otherwise, you'll have to keep coming
back here every step of your development process. If you have a specific
question about Java, we can try to answer it. Otherwise, I can only
recommend that you google for "Java tutorial" and follow the tutorials you
find.

   - Oliver
vunet.us@gmail.com - 19 Oct 2006 17:37 GMT
Oliver,
Your recommendations are stronly considered. By the way, I was always
wondering, what is the reason of being helped on Google Groups? Is it
because some people want to really help others, or there may be
something behind this? I really wonder. Or maybe I have to do something
in return. Please, help me know. Thank you.
Oliver Wong - 19 Oct 2006 18:00 GMT
> Oliver,
> Your recommendations are stronly considered. By the way, I was always
> wondering, what is the reason of being helped on Google Groups? Is it
> because some people want to really help others, or there may be
> something behind this? I really wonder. Or maybe I have to do something
> in return. Please, help me know. Thank you.

   I don't know. You'd probably have to ask a psychology newsgroup for that
one.

   - Oliver
Dag Sunde - 20 Oct 2006 10:44 GMT
> Oliver,
> Your recommendations are stronly considered. By the way, I was always
> wondering, what is the reason of being helped on Google Groups? Is it
> because some people want to really help others, or there may be
> something behind this? I really wonder. Or maybe I have to do
> something in return. Please, help me know. Thank you.

Two answers here...

You're not being helped on "Google Groups"! "Google Groups" is just
a web-site that let you view and post to UseNet newsgroups. Most
experienced people won't even browse into "GG", but use a dedicated
News Client, which is *made* for participating on Usenet.

Second, it is because some people want to really help others.
And because those who help others also learn from the discussions
themselves.

Signature

Dag.

Andrew Thompson - 19 Oct 2006 16:47 GMT
> I am new to Java.

Wow!

>...I need to rewrite a function which gets XML elements
> text as shown below to get elements value instead:

Cool!  When you finish, could you send me the
codes too?

Andrew T.
Steve W. Jackson - 19 Oct 2006 16:55 GMT
> I am new to Java. I need to rewrite a function which gets XML elements
> text as shown below to get elements value instead:
[quoted text clipped - 13 lines]
>
> THANKS TO ALL.

You should become familiar with the API Javadocs, as you'll find a great
part of what you want to know in there.  For this question, start with
<http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html>.

Assuming that the parameter "e" is the element in your (incorrect)
examples named "xml", you can get the value of the attribute named
"value" using:

String value = e.getAttribute("value");

If the attribute doesn't exist or is an empty string, you'll get an
empty string in return.

To get the value of the text node, you could try this:

if (e.getFirstChild().getNodeType() == Node.TEXT_NODE) {
   String nodevalue = e.getFirstChild().getNodeValue();
}

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

vunet.us@gmail.com - 19 Oct 2006 17:16 GMT
Steve,
Your solution is amazing. Thank you.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.