How to use the One-to-One mapping in Java Code
Dear all:
I have set the direct mapping and named query,
and have written web service of login.
I can login successfully.
Now,I want learning about One-to-One mapping.
I have setting the One-to-One mapping,
then what can I do latter?
I do not found any paper showing how to use it in web service?
Somebody help me?thx all.
Following code worked for me:
import oracle.javatools.resourcebundle.BundleFactory;
import java.util.ResourceBundle;
* This method retrieves localized strings from a given XLIF resource bundle.
* @param bundleName The XLIF bundle from which the localized string is to be retrieved.
* @param key The key of the localized string.
* @return The localized string retrieved from the given XLIF bundle.
public static String getXlifLocalizedString(String bundleName, String key) {
if (StringUtils.isEmpty(key)) {
return key;
if (StringUtils.isEmpty(bundleName)) {
return "[" + key + "]";
String localizedString = null;
ResourceBundle resourceBundle = null;
try {
resourceBundle = BundleFactory.getBundle(bundleName);
localizedString = resourceBundle.getString(key);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
return "[" + key + "]";
return localizedString;
}
Similar Messages
-
SSL: How to use the same key pair for ABAP & JAVA?
Hello,
I want to setup an XI (3.0 on Netweaver04)installation in the way, that ABAP AS and JAVA AS use the same key pair for SSL. My problem is to define the same private key on ABAP and JAVA. With the JAVA Administrator I am able to define or import a private key. But I could not find a possibility in ABAP to manage private keys in order to use the same on as in JAVA. What is the procedure for this?
Thanks and Regards,
Frank TottlebenHello,
I want to setup an XI (3.0 on Netweaver04)installation in the way, that ABAP AS and JAVA AS use the same key pair for SSL. My problem is to define the same private key on ABAP and JAVA. With the JAVA Administrator I am able to define or import a private key. But I could not find a possibility in ABAP to manage private keys in order to use the same on as in JAVA. What is the procedure for this?
Thanks and Regards,
Frank Tottleben -
How to get the Weblogic Server Id from within java code
I would like to log which server (among a cluster) a certain job is running on. Is there a way to get the server id from within Java code (this code is in a session bean if that is relevant.)
By server id I mean the "Name" column in the summary of servers on the weblogic console.
Thanks,
kenUse the two entries close to the bottom of the page: "list WebLogic
MBeans:listMBeans.jsp
display MBean attributes and operations:showMBean.jsp"
Nils
Anatoly wrote:
>
Cameron,
That page has these items on it:
which one do you think helps with my issue?
Misc WebLogic examples
LongRunningTask
Execute tasks in parallel using WebLogic Execute Threads
Weblogic stats (5.1)
Reload Servlet(s) programmatically (5.1)
Network classload from WebLogic:using reflection,or the launcher
Weblogic 5.1 debugging properties
Seppuku pattern readme
Using dynamic proxies to intercept EJB invocations (6.1)
list WebLogic MBeans:listMBeans.jsp
display MBean attributes and operations:showMBean
Thanks to Marcelo Caldas for filter by type option and nice UI!
Using com.sun.jdmk.comm.HtmlAdaptorServer with WebLogic 6.1
Cool
EJBGen
Dimitri
back
"Cameron Purdy" <[email protected]> wrote in message news:<3c7a745d$[email protected]>...
JMX ... see http://dima.dhs.org/misc/ for some info on JMX in Weblogic.
Peace,
Cameron Purdy
Tangosol, Inc.
Clustering Weblogic? You're either using Coherence, or you should be!
Download a Tangosol Coherence eval today at http://www.tangosol.com/
"Anatoly" <[email protected]> wrote in message
news:[email protected]..
Does anyone know who to get the managing server URL's port
from within the EJB code running on Weblogic 6.1?
The URL port is not default (not 7001), but when creating
initial context, I am not specifying the URL in properties.
Due to that, trying to the the PROVIDER_URL property from
environment does not return anything.
Appreciate any responses.
-Anatoly
============================
[email protected] -
How to use XLIFF file as resource bundle in Java code
We use xliff as resource bundle for our ADF application. it is has been no problem to have localized message displayed on UI. how ever, I'm wonderring how to use Java code to access xliff as resource bundle which similar to access properties resource bundle. for example:
Locale myLocale = new Locale("es", "ES");
ResourceBundle bundle = ResourceBundle.getBundle("HelloResourceBundle", myLocale);
System.out.println(bundle.getString("Hello"));is it posible to create "HelloResourceBundle" in xliff format?
ThanksFollowing code worked for me:
import oracle.javatools.resourcebundle.BundleFactory;
import java.util.ResourceBundle;
* This method retrieves localized strings from a given XLIF resource bundle.
* @param bundleName The XLIF bundle from which the localized string is to be retrieved.
* @param key The key of the localized string.
* @return The localized string retrieved from the given XLIF bundle.
public static String getXlifLocalizedString(String bundleName, String key) {
if (StringUtils.isEmpty(key)) {
return key;
if (StringUtils.isEmpty(bundleName)) {
return "[" + key + "]";
String localizedString = null;
ResourceBundle resourceBundle = null;
try {
resourceBundle = BundleFactory.getBundle(bundleName);
localizedString = resourceBundle.getString(key);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
return "[" + key + "]";
return localizedString;
} -
Query using the SQL 'go' command on a JAVA code
Hi,
I am trying to create a new database on MS SQL and at the same time verify whether the data base exist already and then add a new table. The query statement works well on the query windows on MS SQL, but when the query is place using a JAVA code it gives the following error:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
at DataBaseCreator.main(DataBaseCreator.java:30)
I have to add that if I only query: "CREATE DATABASE NameOfDatabase" the new data base is created without a problem using JAVA, but when I try to use the following query, I got the error message.
"USE Master "
+ "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
+ " DROP DATABASE DatesTemps"
+ " go "
+ " CREATE DATABASE DatesTemps22 "
+ " go"
+ " USE DatesTemps "
+ " CREATE TABLE Fable ( "
+ " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
+ " Title VARCHAR(50) NOT NULL, "
+ " Moral VARCHAR(100) NOT NULL, "
+ " FableText VARCHAR(1536) NOT NULL, "
+ " BlobType CHAR(3) NULL DEFAULT 'doc', "
+ " Blob IMAGE NULL DEFAULT NULL )"
If it is useful my complete code is the following, I appreciate in advance your comments.
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DataBaseCreator {
public static void main (String[] args)
Connection Time =null;
Statement stmt = null;
String data = "jdbc:odbc:DataBaseCreation";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Time= DriverManager.getConnection(data,"","");
stmt = Time.createStatement();
//String query;
//java.sql.Timestamp ts1 = new java.sql.Timestamp(((3*60)+58)*60*1000);
// System.out.println(ts1 + " This is a Time Stamp");
ResultSet rec = stmt.executeQuery(
"USE Master "
+ "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
+ " DROP DATABASE DatesTemps"
+ " go "
+ " CREATE DATABASE DatesTemps22 "
+ " go"
+ " USE DatesTemps "
+ " CREATE TABLE Fable ( "
+ " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
+ " Title VARCHAR(50) NOT NULL, "
+ " Moral VARCHAR(100) NOT NULL, "
+ " FableText VARCHAR(1536) NOT NULL, "
+ " BlobType CHAR(3) NULL DEFAULT 'doc', "
+ " Blob IMAGE NULL DEFAULT NULL )"
catch( Exception e )
System.err.println( e );
e.printStackTrace();
finally
try
stmt.close();
Time.close();
catch( Exception e )
System.err.println( e );
}Ok, first of all thanks for your answer, now what I want to do is the following:
1) I need to input ((retrieve) every minute some data (Date and Temperature), that I will get from and external device, this is not part of this code.
2) I want to store that data (Date and Temp) on a data base, here where I need the command to create the data base and to verify whether that data base already exists. In case it has already been created then create new table(s) on it. If it doesn't exist then create and then create new tables.
3) Each Day (at yyyy mm dd 00:00:00:000 will create a new table, and the name of this table will be yyyymmdd.
4) Then every minute the java code will retrieve the data and add it to the table in the data base.
5) That will be a close loop that will be running until the user interrupt it.
I haven't make the communication code yet, in order to test my code I was thinking to retrieve the data from another data base. This would be just to verify that the JAVA sequence is able to retrieve the data every minute and create new data base and tables.
For the record I am able to send the queries and retrieve information from SQL running the code in eclipse, that will cover your first observation.
I am quite new in the forum I am sorry I didn't get the use of code tags.
Sorry again as I said I am quite new on this, what's a DDL statement.
Thanks. -
How to use Dlls and Header files in my java Code?
Hi All,
I want to make use of dll and header files of DataStage, from my Java Interface.
i am buliding a product where i need to contact DataStage server from my Java Code alone, For this they provided dlls and header files
Now i wan to make use of them and need to perform DataStage operations from my Java Interface.
Can any on help out me regarding this?Try Java Platform SDK for native function calls without JNI writing code, like it done in .NET languages.
For MS Windows:
http://www.simtel.net/product.php[id]100916[SiteID]simtel.net
For Linux/Unix:
http://www.simtel.net/product.php[id]117719[SiteID]simtel.net -
How to use the date picker in Web dynpro java
Hi,
I want to add date picker to enter a date while developing webdynpro application.
How can i do that.
Regards,
H.V.SwathiHi,
its very simple...
take a input field and map it to the attribute which data type is of "date". thats it at runtime you will see a input filed with date picker.
i.e. Add an inputField and bind the context attribute of Type Date to it
this will show the date picker on screen.
PradeeP -
How to use the google search from inside a java program
Hi guys
How can i use google search in my java program?
What will be the type of the reply i get back from google?
Thanks in advance
[http://javamilestone.blogspot.com/|http://javamilestone.blogspot.com/]Hi,
You have here some examples about how to make search on google from a Java application.
The type of reply is JSON
Here some documentation about it:
[http://code.google.com/apis/ajaxsearch/documentation/#fonje|http://code.google.com/apis/ajaxsearch/documentation/#fonje]
And here some snippets:
[http://code.google.com/apis/ajaxsearch/documentation/#fonje_snippets|http://code.google.com/apis/ajaxsearch/documentation/#fonje_snippets]
Regards,
David. -
How do use the method record(int score) in this code?
how do i use record(int score) from the class Stats to record a new score?
public class ScoreInfo {
private int score;
private int numStudents;
public ScoreInfo(int aScore){
score = aScore;
numStudents=1;
public void increment(){numStudents++;}
public int getScore(){return score;}
public int getFrequency(){return numStudents;}
import java.util.ArrayList;
import java.*;
public class Stats
private ArrayList<ScoreInfo> scoreList;
public boolean record(int score)
int k=0;
while(k<scoreList.size() && score > scoreList.get(k).getScore()){
k++;
boolean found = k<scoreList.size() && score == scoreList.get(k).getScore();
if(found){scoreList.get(k).increment();}
else{scoreList.add(k,new ScoreInfo(score));}
return found;
public void recordScores(int[] stuScores)
static int score = 50;
public static void main(String[] args) throws Exception
Stats stats = new Stats();
ScoreInfo thestat = new ScoreInfo(score);
stats.scoreList.add(thestat);
}hiwa wrote:
In your main() method, or in any code which tries to create a new score, below is wrong:
ScoreInfo thestat = new ScoreInfo(score);
stats.scoreList.add(thestat);They should be:
stats.record(thestat); // record() method creates a new ScoreInfo
// and add it to the scoreList, see your own posted code
stats.record(thestat); will not work because record has a parameter that needs an integer not an object
i tried public static void main(String[] args) throws Exception
Stats stats = new Stats();
ScoreInfo thestat = new ScoreInfo(7);
stats.record(7);
but i get this error Exception in thread "main" java.lang.NullPointerException
at Stats.record(Stats.java:13)
at Stats.main(Stats.java:39) -
JNI - How to use the error reporting mechanism?
I've developed a C++ DLL which is loaded from a commercial Win32 application (not written by me) as a plug-in for external calculations. On its initialization the C++ DLL launches the Java VM via the JNI invocation interface. When the DLL functions are called by the application, they forward the calls to Java objects inside the Java VM, again via JNI invocation interface.
This works well, but I have encountered a weird error.
From Java I open a JFrame containing a JTextArea as small console for debug output messages. If I turn output to this debug console off (my printToConsole routine checks whether a boolean flag is set), the string concatenation operator may lead to a crash of the Java VM.
For example, if in one of the Java functions called from the
DLL via JNI invocation interface the following is the first statement,
it leads to a crash of the Java VM and the application that loaded the C++ proxy DLL.
String test=""+Math.random(); // String test not used later
Interestingly, if I comment this statement out, the Java code works fine WITHOUT any crash. I've already thought about potential races and synchronization issues in my code, but I don't see where this is the case. And the string concatenation error fails as well, if I insert sleep() statements in front of it and at other places in the code. However, if I turn on log messages printed to my JFrame debug console (containing a JTextArea), the String concatenation works without problems.
So maybe the JNI interface has a bug and affects the Java VM; I don't see where my JNI code is wrong.
One problem is that I do not get any stdout output, as the C++ proxy DLL is loaded by the Windows application, even if I start the Windows application from the DOS command line (under Windows).
Does anyone know how to use the error reporting mechanism?
http://java.sun.com/j2se/1.4.2/docs/guide/vm/error-handling.html
Is it possible that the JVM, when it crashes, writes debug information about the crash into a file instead of stdout/stderr?
My C++ proxy DLL was compiled in debug mode, but the commercial application (which loaded the DLL) is very likely not.
I do not know hot to find the reason why the String concatenation fails inside the Java function called from the C++ DLL via JNI.Yes, I've initially thought about errors in the C++ code too. But the C++ code is actually very simple and short. It doesn't allocate anything on the C++ side. It allocates a couple of ByteBuffers inside the Java VM however via JNI invocation interface calls of env->NewDirectByteBuffer(). The native memory regions accessed via the ByteBuffers are allocated not by my own C++ code, but by the program that calls my DLL (the program is Metastock).
The interesting thing is that everything works fine if output to my debug console is enabled, which means that in the Java print routine getConsoleLoggingState() returns true and text is appended to the jTextArea.
static synchronized void print(String str)
{ MetaStockMonitor mMon=getInstance();
if ( mMon.getFileLoggingState() && mMon.logFileWriter!=null) {
mMon.logFileWriter.print(str);
mMon.logFileWriter.flush();
if ( mMon.getConsoleLoggingState() ) {
mMon.jTextArea1.append(str);
Only if output to the JTextArea is turned off (ie. getConsoleLoggingState()==false), the crash happens when the FIRST statement in the Java routine called via JNI invocation interface is a (useless) String concatenation operation, as described above.
String test=""+Math.random(); // String test not used later
Moreover, the crash happens BEFORE the allocated ByteBuffer objects are accessed in the Java code. But again, if console output is turned on, it works stable. If console output is turned off, it works when the (useless) String concatenation operation is removed in the Java routine called from C++.
I've already thought about potential races (regarding multiple threads), but this can be ruled out in my case. It almost appears as if the JVM can have problems when called by the invocation interface (I tested it with Java 1.4.2 b28).
All the calls between C++ and Java go ALWAYS in the direction from C++ code to Java. Unfortunately, there is no special JRE version with extensive logging capabilities to facilitate debugging. And the problem is not easily reproducible either.
JNIEnv* JNI_GetEnv()
JNIEnv *env;
cached_jvm->AttachCurrentThread((void**)&env,NULL);
fprintf(logfile,"env=%i\n",env);
fflush(logfile);
return env;
// function called by Metastock's MSX plug-in interface
BOOL __stdcall createIndEngine (const MSXDataRec *a_psDataRec,
const MSXDataInfoRecArgsArray *a_psDataInfoArgs,
const MSXNumericArgsArray *a_psNumericArgs,
const MSXStringArgsArray *a_psStringArgs,
const MSXCustomArgsArray *a_psCustomArgs,
MSXResultRec *a_psResultRec)
a_psResultRec->psResultArray->iFirstValid=0;
a_psResultRec->psResultArray->iLastValid=-1;
jthrowable ex;
jmethodID mid;
JNIEnv* env=JNI_GetEnv();
jobject chart=getChart(env, a_psDataRec);
if ( chart==NULL) {
return MSX_ERROR;
jobject getChart (JNIEnv* env, const MSXDataRec *a_psDataRec)
jthrowable ex;
jmethodID mid;
int closeFirstValid, closeLastValid;
closeFirstValid=a_psDataRec->sClose.iFirstValid;
closeLastValid=a_psDataRec->sClose.iLastValid;
long firstDate, firstTime;
if (closeFirstValid>=1 && closeFirstValid<=closeLastValid) {
firstDate = a_psDataRec->psDate[closeFirstValid].lDate;
firstTime = a_psDataRec->psDate[closeFirstValid].lTime;
} else {
firstDate=0;
firstTime=0;
jclass chartFactoryClass = env->FindClass("wschwendt/metastock/msx/ChartFactory");
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot find class ChartFactory\n");
printSBufViaJava(sbuf);
return NULL;
mid = env->GetStaticMethodID(chartFactoryClass, "getInstance", "()Lwschwendt/metastock/msx/ChartFactory;");
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot find method ID for ChartFactory.getInstance()\n");
printSBufViaJava(sbuf);
return NULL;
jobject chartFactory=env->CallStaticObjectMethod(chartFactoryClass, mid);
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Exception while calling ChartFactory.getInstance()");
printSBufViaJava(sbuf);
return NULL;
mid = env->GetMethodID(chartFactoryClass, "getChartID", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;IIIIIII)F");
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot find method ID for ChartFactory.getChartID()\n");
printSBufViaJava(sbuf);
return NULL;
jobject symbolBuf=env->NewDirectByteBuffer(a_psDataRec->pszSymbol, strlen(a_psDataRec->pszSymbol) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate symbolBuf\n");
printSBufViaJava(sbuf);
return NULL;
jobject securityNameBuf=env->NewDirectByteBuffer(a_psDataRec->pszSecurityName, strlen(a_psDataRec->pszSecurityName) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate securityNameBuf\n");
printSBufViaJava(sbuf);
return NULL;
jobject securityPathBuf=env->NewDirectByteBuffer(a_psDataRec->pszSecurityPath, strlen(a_psDataRec->pszSecurityPath) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate securityPathBuf\n");
printSBufViaJava(sbuf);
return NULL;
jobject securityOnlineSourceBuf=env->NewDirectByteBuffer(a_psDataRec->pszOnlineSource, strlen(a_psDataRec->pszOnlineSource) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate onlineSourceBuf\n");
printSBufViaJava(sbuf);
return NULL;
// Java Function call leads to crash, if console output is turned off and
// the first statement in the Java routine is a (useless) string concatenation.
// Otherwise it works stable.
jfloat chartID=env->CallFloatMethod(chartFactory, mid, securityNameBuf, symbolBuf,
securityPathBuf, securityOnlineSourceBuf, (jint)(a_psDataRec->iPeriod),
(jint)(a_psDataRec->iInterval), (jint)(a_psDataRec->iStartTime),
(jint)(a_psDataRec->iEndTime), (jint)(a_psDataRec->iSymbolType),
(jint)firstDate, (jint)firstTime );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Exception while calling ChartFactory.getChartID()");
printSBufViaJava(sbuf);
return NULL; -
How can I use the button in one panel to control the other panel's appearing and disappearing?
How can I use the button in one panel to control the other panel's
appearing and disappearing? What I want is when I push the button on
one button . another panel appears to display something and when I
push it again, that the second panel disappears.> How can I use the button in one panel to control the other panel's
> appearing and disappearing? What I want is when I push the button on
> one button . another panel appears to display something and when I
> push it again, that the second panel disappears.
>
You want to use a combination of three features, a button on the panel,
code to notice value changes using either polling in a state machine of
some sort or an event structure, and a VI Server property node to set
the Visible property of the VI being opened and closed.
The button exists on the controlling panel. The code to notice value
changes is probably on the controlling panel's diagram, and this diagram
sets the Visible property node of a VI class property node to FALSE or
TRUE to show or
hide the panel. To get the VI reference to wire to the
property node, you probably want to use the Open VI Reference node with
the VI name.
Greg McKaskle -
Hello all,
when i update apps on my iphone they need the ID that i used when i downloaded these apps and i forgot this ID and a make a new ID
How i used the new one to update these apps?
thanksYour device can hold apps from multiple IDs, but to update them you have to swicth identities which is time consuming. If possible use only the one ID. If you need to reset the password for your old ID visit My Apple ID.
tt2 -
Does anyone know how to use the earphones( plugs) that come with iPhones?
Mine is still fairly new and I am just learning how to use certain things.They're pretty straightforward. You plug them into the headset jack (the hole on the top left of your phone). You put the buds in your ears. All sounds, except for the phone ringing will now come through the earbuds.
-
How to use the variables used in the message mapping
Hi ,
In the message mapping we can declare variables in the JAVA section , these variables could be used across the mapping .
I have tried using it but I am unable to retrieve the values assigned to the variables in one UDF into the another UDF .
Please guide me how to use the variables declared in the JAVA section in the message mapping .
Thanks
Anita YadavAnita,
I have worked on the Global variables and i found no issues. Make sure that the variable is declared in the Declaration Section and then initlaized in the Initialization section.
If you declare a variable in the Declaration Section ,
int i;
then in any udf you can use if directly. No need to re declare the variable in the UDF. If you do this, then it becomes a local variable.
Regards,
Bhavesh -
How to use multiple ipods on one account
I have an Ipod classic and just bought my sons two nano's how do I use these on the same account without changing my account info?
Take a look here:
How to use multiple iPods with one computer
Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Discussions page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums, in the User Tips Library and in the Apple Knowledge Base before you post a question.
Regards. -
How to read the content in one node of XML in Java? Pls help
My dear brothers,
I am a newbie of XML, I have a exercise which is creating a Tree View from XML file. But the trouble is I do not know how to read the content in one node of XML file. I decide to use the algorithm as following:
1. Create a GUI form which gives the ability for user to choose a XML file (ok)
2. Load XML and return the file (ok)
3. Read the file from node to node to create the node in Tree View (?!)
Please help me, and if you are enough kind, please give me an small example to easy understand. Thanks in advance.
Hoang Yen BinhI hope this one helps you.
<ABC Type="ProductBased" ProdName="One" Location="India">
<CEO>Raj</CEO>
<Finance>Vikram</Finance>
<HR>Karthik</HR>
<Technical>Satish</Technical>
</ABC>
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Attr;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.DOMException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
public class XmlReading {
Document doc;
Element element;
public static void main(String[] args) throws Exception{
XmlReading xr = new XmlReading();
xr.getXmlParser(args);
public void getXmlParser(String[] args) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
if(args.length != 1) {
System.err.println("Argument Required");
try {
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(new File(args[0]));
}catch(ParserConfigurationException e1) {
}catch(SAXException e2) {
}catch(IOException e3) {
getAttributes();
public void getAttributes() {
// Retrive the entire Document from the Dom Tree
element = doc.getDocumentElement();
// System.out.println(element);
NamedNodeMap attrs = element.getAttributes();
// Get number of attributes in the element
int numAttrs = attrs.getLength();
// Process each attribute
for (int i=0; i<numAttrs; i++) {
Node node = attrs.item(i);
// Get attribute name and value
String attrName = node.getNodeName();
String attrValue = node.getNodeValue();
System.out.println(attrName + ": " + attrValue);
String s1 = element.getTagName();
System.out.println(s1);
// To get all the elements in a DOM Tree
NodeList nl1 = element.getElementsByTagName("*");
int i2 = nl1.getLength();
System.out.println(i2);
for(int i=0; i<i2; i++) {
System.out.println(nl1.item(i) + "\n");
}
Maybe you are looking for
-
Difference between OBIEE Logical Modelling and physical modelling
HI. what is the difference between logical modeling (BMM) and physical modelling(Physical layer) in obiee admin tool please narrate it in definition format thank you rakesh
-
Hi, I have created a report and have enabled the prefiltering option. But still when i select a particular record to run, it gives an error. Is there anything that needs to be changed in the xml query. Can someone please show me a detailed example of
-
SQL Developer 3.2 does not show warnings
In SQL developer 3.2, I am trying to compilie package. After compilation it shows following message in script output PACKAGE BODY package_name_pkg compiled Warning: execution completed with warning Everytime I need to use 'SHOW ERRORS' command to see
-
I can't empty the trash I have three different versions of Quicken Essentials that should have been deleted and also some iskysoft apps [two ]. I tries to delete them but I always get a -8003 error. I ve tried using the terminal with both the sudo an
-
Use generated file metadata in export name
When exporting it would be useful to have access to metadata about the exported file (horizontal and vertical resolution as well as the name of the export preset used) to include in the export file name. e.g. {filename}-{ExportVertSize}x{ExportHorizS