Extracting value from XML tags in Java
Hi all,
I need to extract the value from a string (XML Format). Eg. <Name>Ray</Name> and displaying Name: Ray
The string value is like any other String class object except that it is format with XML tags. I have quite a few examples that shows how a value can be read from a .xml file but none that describe how to get a value from a String object.
Thanks in advance.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse("Your XML Goes here ");
Similar Messages
-
How to get the values from xml file to java combo box
Hi frens,
I am new to java and xml programming,
Now, i want to have a code of getting the tag values from the xml file
into the swing combo box of java front end.
How can we do that?
any help of code or tutorial or an ebook is a great help for me.
Thank you,
Karthik.
Edited by: Karthik84 on Aug 27, 2008 1:49 AM
Edited by: Karthik84 on Aug 27, 2008 11:29 PMlook at this link
http://www.stylusstudio.com/docs/v2006/d_help30.html
I read sometime back that castor has a tool to do
conversion. You might have a look into casto as well. -
Regular expression to extract value from xml
Hi,
I need to extract the value of an XML tag.
<purchaseId>Best-200423</purchaseId>
The result of the expression should be: "Best-200423".
Something like this ([^\\<purchaseId\\>]*[^\\</purchaseId\\>]) does not work.
Does somebody has a soltuion?
I can't get it to work! I want to use the Java Regular Expression functionality.
Best wishes
JochenYou got lucky, is all. Try changing "Best" to "pest" in your example and it won't work. The square brackets are spurious, and you want m.getGroup(1) to get the stuff that matches the () group.
Square brackes mean "match any of the characters in the brackets". [^ means "match any character not in this list"). -
Help needed in extracting values from XML
SAMPLE XML:
- <Form1>
- <Name>
<Ttl>MR</Ttl>
<Fore>ABC1</Fore>
<Sur>XYZ2</Sur>
</Name>
- <Address>
<Line>ADD_LINE_1</Line>
<Line>ADD_LINE_2</Line>
<PostCode>PST CDE</PostCode>
</Address>
<BirthDate>0001-01-01</BirthDate>
- <Details>
<TotalEarnings>1234567.00</TotalEarnings>
<TotalDeduction>12345.00</TotalDeduction>
</Details>
</Form1>
- <Form1>
- <Name>
<Ttl>MR</Ttl>
<Fore>ABC2</Fore>
<Sur>XYZ2</Sur>
</Name>
- <Address>
<Line>ADD_LINE_3</Line>
<Line>ADD_LINE_4</Line>
<PostCode>PST CDE</PostCode>
</Address>
<BirthDate>0002-02-02</BirthDate>
<Gender>female</Gender>
- <Details>
<TotalEarnings>12345.00</TotalEarnings>
<TotalDeduction>123.00</TotalDeduction>
</Details>
</Form1>
There can be any 'n' number of <Form1>'s in one XML.But I want to get only the details of the person whose TotalEarnings>1million. Details include
Name->Ttl,Fore,Sur
which in this case would be MR,ABC1,XYZ1
Address->Line,Line,Postcode
which in this case would be ADD_LINE_1,ADD_LINE_2,PST CDE
Birthdate
which in this case would be 0001-01-01
Gender
which in this case would be "null" as there is no Gender tag present
Details->TotalEarnings,TotalDeduction
which in this case would be 1234567.00,12345.00
The technique I was using is,
1. Convert to clob
2. User dbms_instr find the location of <Form1> in a loop
3. For every occurence of <Form1> I find <TotalEarnings> value and check if this is greater than 1 million.
4. If true, I use dbms_instr to get the values of all the tags inside <Form1>
5. The drawback of using dbms_instr is that it gets the value of first occurence of whatever sting we supply.In this case dbms_instr(xml,'<Gender>',position of Form1) will not return null whereas it will return "Female" from the next form. This is wrong as it doesnt belong to the person who earns more than a million.
Can anyone suggest a way to fetch the values that only belong to the form of the person who earns more than a million?There can be any 'n' number of <Form1>'s in one
XML.Not if you want the XML to be valid there can't. You would need a root element around all the <Form1>'s to make it valid.
The technique I was using is,
1. Convert to clob
2. User dbms_instr find the location of <Form1> in a
loop
3. For every occurence of <Form1> I find
<TotalEarnings> value and check if this is greater
than 1 million.
4. If true, I use dbms_instr to get the values of all
the tags inside <Form1>
5. The drawback of using dbms_instr is that it gets
the value of first occurence of whatever sting we
supply.In this case
dbms_instr(xml,'<Gender>',position of Form1) will not
return null whereas it will return "Female" from the
next form. This is wrong as it doesnt belong to the
person who earns more than a million.
Can anyone suggest a way to fetch the values that
only belong to the form of the person who earns more
than a million?Why on earth are you using dbms_instr for this? Oracle has built in XML functionality for use against XMLTYPE data, such as the ExtractValue method and the use of XPATH expressions.
I'd suggest you start reading some of the manuals regarding XML functionality in Oracle rather than trying to manually parse it all. -
Extracting Values from XML-Document in pl/sql
Hello!
I need to extract the content of the following extract:
<ns1:OXERPGetArticlesResponse xmlns:ns1="OXERPService">
<ns1:OXERPGetArticlesResult>
<ns1:OXERPType>
<ns1:aResult>
<ns1:ArrayOfString>
<ns1:string>OXID</ns1:string>
<ns1:string>531f91d4ab8bfb24c4d04e473d246d0b</ns1:string>
</ns1:ArrayOfString>
<ns1:ArrayOfString>
<ns1:string>OXARTNUM</ns1:string>
<ns1:string>0601-85-069</ns1:string>
</ns1:ArrayOfString>
<ns1:ArrayOfString>
<ns1:string>OXPRICE</ns1:string>
<ns1:string>100.5</ns1:string>
</ns1:ArrayOfString>
</ns1:aResult>
<ns1:blResult>true</ns1:blResult>
<ns1:sMessage/>
</ns1:OXERPType>
<ns1:OXERPType>
<ns1:aResult>
<ns1:ArrayOfString>
<ns1:string>OXID</ns1:string>
<ns1:string>531a8af7d9a9a5bb53b65a2b9a5356e5</ns1:string>
</ns1:ArrayOfString>
<ns1:ArrayOfString>
<ns1:string>OXARTNUM</ns1:string>
<ns1:string>0601-85-069-1</ns1:string>
</ns1:ArrayOfString>
<ns1:ArrayOfString>
<ns1:string>OXPRICE</ns1:string>
<ns1:string>89.9</ns1:string>
</ns1:ArrayOfString>
</ns1:aResult>
<ns1:blResult>true</ns1:blResult>
<ns1:sMessage/>
</ns1:OXERPType>
</ns1:OXERPGetArticlesResult>
</ns1:OXERPGetArticlesResponse>
The output should be:
OXID OXARTNUM OXPRICE
531f91d4ab8bfb24c4d04e473d246d0b 0601-85-069 100.5
531a8af7d9a9a5bb53b65a2b9a5356e5 0601-85-069-1 89.9
The count of rows and columns is variable.
I want to do this by using xmltype.extract but I found no way to create a loop over the content of the xml document.
Hopefully someone can help me!
Regards
HerbertOK, then you should be able to use something like :
SQL> var xmldoc clob;
SQL> begin
2 :xmldoc := '<ns1:OXERPGetArticlesResponse xmlns:ns1="OXERPService">
3 <ns1:OXERPGetArticlesResult>
4 <ns1:OXERPType>
5 <ns1:aResult>
6 <ns1:ArrayOfString>
7 <ns1:string>OXID</ns1:string>
8 <ns1:string>531f91d4ab8bfb24c4d04e473d246d0b</ns1:string>
9 </ns1:ArrayOfString>
10 <ns1:ArrayOfString>
11 <ns1:string>OXARTNUM</ns1:string>
12 <ns1:string>0601-85-069</ns1:string>
13 </ns1:ArrayOfString>
14 <ns1:ArrayOfString>
15 <ns1:string>OXPRICE</ns1:string>
16 <ns1:string>100.5</ns1:string>
17 </ns1:ArrayOfString>
18 </ns1:aResult>
19 <ns1:blResult>true</ns1:blResult>
20 <ns1:sMessage/>
21 </ns1:OXERPType>
22 <ns1:OXERPType>
23 <ns1:aResult>
24 <ns1:ArrayOfString>
25 <ns1:string>OXID</ns1:string>
26 <ns1:string>531a8af7d9a9a5bb53b65a2b9a5356e5</ns1:string>
27 </ns1:ArrayOfString>
28 <ns1:ArrayOfString>
29 <ns1:string>OXARTNUM</ns1:string>
30 <ns1:string>0601-85-069-1</ns1:string>
31 </ns1:ArrayOfString>
32 <ns1:ArrayOfString>
33 <ns1:string>OXPRICE</ns1:string>
34 <ns1:string>89.9</ns1:string>
35 </ns1:ArrayOfString>
36 </ns1:aResult>
37 <ns1:blResult>true</ns1:blResult>
38 <ns1:sMessage/>
39 </ns1:OXERPType>
40 </ns1:OXERPGetArticlesResult>
41 </ns1:OXERPGetArticlesResponse>';
42 end;
43 /
Procédure PL/SQL terminée avec succès.
SQL> SELECT x1.rec_id
2 , x2.col_name
3 , x2.col_value
4 FROM XMLTable(
5 XMLNamespaces('OXERPService' as "ns1"),
6 '/ns1:OXERPGetArticlesResponse/ns1:OXERPGetArticlesResult/ns1:OXERPType/ns1:aResult'
7 passing xmltype(:xmldoc)
8 columns rec_id for ordinality
9 , rec_xml xmltype path 'ns1:ArrayOfString'
10 ) x1,
11 XMLTable(
12 XMLNamespaces('OXERPService' as "ns1"),'/ns1:ArrayOfString'
13 passing x1.rec_xml
14 columns col_name varchar2(30) path 'ns1:string[1]'
15 , col_value varchar2(30) path 'ns1:string[2]'
16 ) x2
17 ;
REC_ID COL_NAME COL_VALUE
1 OXID 531f91d4ab8bfb24c4d04e473d246d
1 OXARTNUM 0601-85-069
1 OXPRICE 100.5
2 OXID 531a8af7d9a9a5bb53b65a2b9a5356
2 OXARTNUM 0601-85-069-1
2 OXPRICE 89.9
6 ligne(s) sélectionnée(s).You mentioned that the number of column(s) is not known in advance. That's gonna be a problem to present the data column-wise.
Version 11g has the PIVOT feature, but still you have to know how many columns there will be in the result set.
How are you going to use the data after extraction?
Maybe we could advise some other techniques more relevant for your requirement. -
How to Get and Update properties values from XML tag Using Xquery or PL Sql
Hi
I have this tag
<Solicitud Pais = "1">
How i can get Pais value?
How i can update Pais Value?
Y can use Xquery funtions or PL SQL for this?
Thak's
AngelHow i can get Pais value? ExtractValue
How i can update Pais Value?UpdateXML
Y can use Xquery funtions or PL SQL for this?Yes
Without knowing more about your requirements, where information resides, or even a version of Oracle, that is the best I'll do. -
Extract value from XML column .
Hi,
I'm on 11.2.0.3 and got query
select other_xml from v$sql_plan where sql_id=’2y32qkr40b82a’ and other_xml is not null
<other_xml><info type="db_version">11.2.0.3</info>
<info type="parse_schema"><![CDATA["LIU"]]></info><info type="dynamic_sampling">2</info>
<info type="plan_hash">3882242470</info><info type="plan_hash_2">281948136</info>
<peeked_binds><bind nam=":N1" pos="1" dty="2" pre="0" scl="0" mxl="22">c30d51</bind>
<bind nam=":N2" pos="2" dty="2" pre="0" scl="0" mxl="22">c30d51</bind>
<bind nam=":N3" pos="3" dty="2" pre="0" scl="0" mxl="22">c30d51</bind></peeked_binds>
<outline_data><hint><![CDATA[IGNORE_OPTIM_EMBEDDED_HINTS]]></hint>
<hint><![CDATA[OPTIMIZER_FEATURES_ENABLE('11.2.0.3')]]></hint>
<hint><![CDATA[DB_VERSION('11.2.0.3')]]></hint>
<hint><![CDATA[FIRST_ROWS(100)]]></hint>
<hint><![CDATA[OUTLINE_LEAF(@"SEL$1")]]></hint>
<hint><![CDATA[FULL(@"SEL$1" "LIU"@"SEL$1")]]></hint>
</outline_data></other_xml>I want output related to <info type="dynamic_sampling">2</info> :
column name dynamic_sampling
row value 2
on the second thought using dynamic_sampling value as a predicate would be great so:
select * from v$sql_plan
where
dynamic_sampling = 2
how to transform other_xml column to have such results ?
Regards
GregG
Edited by: GregG on Feb 8, 2013 1:14 PMAnd here is an xmltable version:
select p.sql_id, t.val
from v$sql_plan p
, xmltable('for $i in /other_xml/info
where $i/@type eq "dynamic_sampling"
return $i'
passing xmltype(p.other_xml)
columns attr varchar2(50) path '@type',
val varchar2(50) path '/') t
where p.other_xml is not null;This works for me in 11.2.0.3 but crashes in 11.1.0.7 with ORA-00600: internal error code, arguments: [qctVCO:csform], [0], [0], [0], [0], [112], [2], [224], [], [], [], [] -
Need help in extracting value from an xml tag.
Hi ALL,
Good Morning to all, i have problem in fetching a value from a xml tag. I have created a xml schema based on the schema i have created a xmltype table and inserted a value to the table. When i am trying to fetch a value from a particular tag i am unable to do so.. Kindly help me to solve this. Here by i am posting all the workings i have done...
I am using the following client:
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jan 31 11:44:59 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
////////////////////////////////// XML Schema ///////////////////////
begin
dbms_xmlschema.registerSchema(
'http://www.oradev.com/chipsxml.xsd',
'<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.oradev.com/chipsxml.xsd"
xmlns:samp="http://www.oradev.com/chipsxml.xsd"
version="1.0">
<element name="Field1">
<complexType>
<sequence>
<element name="UTI">
<complexType>
<sequence>
<element name = "U01" type = "string"/>
<element name = "U02" type = "string"/>
<element name = "U03" type = "string"/>
<element name = "U03a" type = "string"/>
<element name = "U03b" type = "string"/>
<element name = "U03c" type = "string"/>
<element name = "U04" type = "string"/>
<element name = "U05" type = "string"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>',
TRUE, TRUE, FALSE, FALSE);
end;
////////////////////////// Table which has multiple Column //////////////////////////
CREATE TABLE chipsxmltable1 (
id number, XMLDATA XmlType)
XMLTYPE XMLDATA STORE AS OBJECT RELATIONAL
XMLSCHEMA "http://www.oradev.com/chipsxml.xsd"
ELEMENT "Field1";
///////////////////////////////// Insert Query in chipsxmltable //////////////////////////
INSERT INTO chipsxmltable VALUES(
xmltype.createxml('<?xml version="1.0"?>
<samp:Field1 xmlns:samp="http://www.oradev.com/chipsxml.xsd" >
<UTI>
<U01>No</U01>
<U02>Y</U02>
<U03>Y</U03>
<U03a>Y</U03a>
<U03b>Y</U03b>
<U03c>Y</U03c>
<U04>Y</U04>
<U05>Y</U05>
</UTI>
</samp:Field1>'));
To show the data as a field with structure:
1. Query:
Select * from chipsxmltable1;
Output:
ID XMLDATA
1 <?xml version="1.0"?>
<samp:Field1 xmlns:samp="http://www.oradev.com/chipsxml.xsd">
<UTI>
<U01>No</U01>
<U02>No</U02>
<U03>Y</U03>
<U03a>Y</U03a>
<U03b>Y</U03b>
<U03c>Y</U03c>
<U04>Y</U04>
<U05>Y</U05>
</UTI>
</samp:Field1>
2. Query: (Both the query displays the same Output)
SELECT X.xmldata.getClobVal() "XMLDATA" FROM chipsxmltable1 X;
select extract(XMLDATA, '/Field1').getstringval() "XMLDATA" from chipsxmltable1 x;
Output:
XMLDATA
<?xml version="1.0"?>
<samp:Field1 xmlns:samp="http://www.oradev.com/chipsxml.xsd">
<UTI>
<U01>No</U01>
<U02>No</U02>
<U03>Y</U03>
<U03a>Y</U03a>
<U03b>Y</U03b>
<U03c>Y</U03c>
<U04>Y</U04>
<U05>Y</U05>
</UTI>
</samp:Field1>
To show the data as a single string without structure using "getstringval()":
3. Query
select extract(XMLDATA, '//text()').getstringval() "CHIPS - XML" from chipsxmltable1 x;
OUtput:
CHIPS - XML
NoNoYYYYYY
To show the data as a single string without structure using "getclobval()":
4.Query
select extract(XMLDATA, '//text()').getClobVal() "CHIPS - XML" from chipsxmltable1 x;
Output:
CHIPS - XML
NoNoYYYYYY
To show the data in a particular tag with/Without structure (Which is not working) using "EXTRACT" function:
6.Query:
select extract(XMLDATA, '/Field1/text()').getstringval() "XMLDATA" from chipsxmltable1 x;
select extract(XMLDATA, '/Field1/UTI').getstringval() "XMLDATA" from chipsxmltable1 x;
select extract(XMLDATA, '/Field1/UTI/U01').getstringval() "XMLDATA" from chipsxmltable1 x;
select extract(XMLDATA, '/Field1/UTI/U01/text()').getstringval() "XMLDATA" from chipsxmltable1 x;
Output:
CHIPS - XML
The above queries are not fetching the value.
To show the data in a particular tag with/Without structure (Which is not working) using "EXTRACTVALUE" function:
7. Query:
select extractValue(XMLDATA, '/Field1/UTI') "XMLDATA" from chipsxmltable1 x;
select extractValue(XMLDATA, '/Field1/UTI/U01') "XMLDATA" from chipsxmltable1 x;
Output:
X
The above queries are not fetching the value.
My question is:
How to fetch values from xml tag when the value are inserted through xml schema?
Apologies if the description is not clear. Kindly let me know if further details are needed. Many thanks for your help.
Very best regards,
Godwin Jebakumar C.V.Hi,
You need to declare the namespace of each element used in the XPath expression, like this :
SQL> select extractvalue( XMLDATA
2 , '/samp:Field1/UTI/U01'
3 , 'xmlns:samp="http://www.oradev.com/chipsxml.xsd"' ) "XMLDATA"
4 from chipsxmltable1 x
5 ;
XMLDATA
No
SQL> select extract( XMLDATA
2 , '/samp:Field1/UTI'
3 , 'xmlns:samp="http://www.oradev.com/chipsxml.xsd"'
4 ).getstringval() "XMLDATA"
5 from chipsxmltable1 x
6 ;
XMLDATA
<UTI>
<U01>No</U01>
<U02>Y</U02>
<U03>Y</U03>
<U03a>Y</U03a>
<U03b>Y</U03b>
<U03c>Y</U03c>
<U04>Y</U04>
<U05>Y</U05>
</UTI>
Please see EXTRACT and EXTRACTVALUE documentation :
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions051.htm#i1006712
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions052.htm#SQLRF06173
BTW, "XMLDATA" is a pseudo-column used by Oracle. I don't know if it'll ever cause any conflict but maybe you should rename your column.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns010.htm#SQLRF00256
Regards. -
Passing Parameters from XML file to Java Application
Can any one help me to know the way of passing values from XML file to Java Application..
Thanx in advanceWith the Processing Instructions <?name pidata?>
Get the Nodes in a Document.
Node node;
if(node.getNodeType()==Node.PROCESSING_INSTRUCTION_NODE)
//String param=node.getData(); -
Extracting data from a tag of xml file which is(xml) in a Field of Csv.
We have a xlm script which is stored in the clob column of the csv file. we have to extract one value from the <tag> and reject remaining data.
Sample:-
<ROW>
<ID>100</ID>
<ORDER_DATE>2000.12.20</ORDER_DATE>
<SHIPTO_NAME>Adrian Howard</SHIPTO_NAME>
<SHIPTO_STREET>500 Marine World Parkway</SHIPTO_STREET>
<SHIPTO_CITY>Redwood City</SHIPTO_CITY>
<SHIPTO_STATE>CA</SHIPTO_STATE>
<SHIPTO_ZIP>94065</SHIPTO_ZIP>
</ROW>
Required Output:-
We have to extract the "500 Marine World Parkway"
from tag <SHIPTO_STREET>
and the above sample xml file is in one of the column which is clob datatype
Any idea How to perform the above activity in PL/SQL ?As BP suggested you can use an XPATH query to extract that information from your XML. However it depends a bit on your XML data.
Here are two examples:
one row XML
select extractvalue(xmltype('<ROW>
<ID>100</ID>
<ORDER_DATE>2000.12.20</ORDER_DATE>
<SHIPTO_NAME>Adrian Howard</SHIPTO_NAME>
<SHIPTO_STREET>500 Marine World Parkway</SHIPTO_STREET>
<SHIPTO_CITY>Redwood City</SHIPTO_CITY>
<SHIPTO_STATE>CA</SHIPTO_STATE>
<SHIPTO_ZIP>94065</SHIPTO_ZIP>
</ROW>')
,'//SHIPTO_STREET/text()') as result
from dual;
RESULT
500 Marine World Parkway
multi rows XML
select extractvalue(column_value,'SHIPTO_STREET/text()') as result
from table(xmlsequence(extract(xmltype('<ROWS>
<ROW>
<ID>100</ID>
<ORDER_DATE>2000.12.20</ORDER_DATE>
<SHIPTO_NAME>Adrian Howard</SHIPTO_NAME>
<SHIPTO_STREET>500 Marine World Parkway</SHIPTO_STREET>
<SHIPTO_CITY>Redwood City</SHIPTO_CITY>
<SHIPTO_STATE>CA</SHIPTO_STATE>
<SHIPTO_ZIP>94065</SHIPTO_ZIP>
</ROW>
<ROW>
<ID>200</ID>
<ORDER_DATE>2000.12.20</ORDER_DATE>
<SHIPTO_NAME>Adrian Howard</SHIPTO_NAME>
<SHIPTO_STREET>Test</SHIPTO_STREET>
<SHIPTO_CITY>Redwood City</SHIPTO_CITY>
<SHIPTO_STATE>CA</SHIPTO_STATE>
<SHIPTO_ZIP>94065</SHIPTO_ZIP>
</ROW>
</ROWS>'
),'ROWS/ROW/SHIPTO_STREET')));
RESULT
500 Marine World Parkway
Test -
How to extract data from xml and insert into Oracle table
Hi,
I have a large xml file. which will have hundreds of the following transaction tags having column names and there values.
There is a table one of the schema with coulums "actualCostRate","billRate"....etc.
I need to extract the values of these columns and insert into the table
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuUK" chargeCode="LCOCD1" externalID="L-RESCODE_UK1-PROJ_UK_CNT_GBP-37289-8" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-12" transactionType="L" units="11" taskID="5017601" inputTypeCode="SALES" groupId="123" voucherNumber="ABCVDD" transactionClass="ABCD"/>
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuEU" chargeCode="LCOCD1" externalID="L-RESCODE_US1-PROJ_EU_STD2-37291-4" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-04" transactionType="L" units="4" taskID="5017601" inputTypeCode="SALES" groupId="124" voucherNumber="EEE222" transactionClass="DEFG"/>Re: Insert from XML to relational table
http://www.google.ae/search?hl=ar&q=extract+data+from+xml+and+insert+into+Oracle+table+&btnG=%D8%A8%D8%AD%D8%AB+Google&meta= -
Im fairly new to XML & web services so bear with me please.
Im trying to extract data from XML documents where the structure/element names are unknown.
The condition for extracting data is if keyword matches some data content.
Im using Java and the DOM API with xcerces and I've managed to parse the XML file, what I need to do next is to traverse the data content checking against keywords and if a keyword matches then to strip the tags and save the data locally ?
Ive trawled through all the documentaion but as theres so many different methods Im somewhat unsuare which is the best way to proceed.
thankstough question, i would suggest looking at jdom as solution for you, because it is a relatively simple one to use for searching through a dom. aside from that, its probably up to you what sort of logic you want to use.
-
How to get string value from xml in JSF??
In JSF How to get string value from xml, .ini and properties file. I want to get string value from xml or text to JSF
Just use the appropriate API's for that. There are enough API's out which can read/parse/write XML, ini and properties files. E.g. JAXP or DOM4J for xml files, INI4J for ini files and Sun's own java.util.Properties for propertiesfiles.
JSF supports properties files as message bundle and resource bundle so that you can use them for error messages and/or localization. -
How to retrieve value from xml file
hi all,
can somebody pls tell me how to retrieve value from xml file using SAXParser.
I want to retrieve value of only one tag and have to perform some validation with that value.
it's urgent .
pls help me out
thnx in adv.
rituhi shanu,
the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
pls have a look at the following code snippet.
public class XMLValidator {
static ArrayList strXXX = new ArrayList();
public void validate(){
factory.setValidating(true);
parser = factory.newSAXParser();
//all factory code is here only
parser.parse(xmlURI, new XMLErrorHandler());
public void setXXX(String pstrXXX){
strUpn.add(pstrXXX);
public ArrayList getXXX(){
return strXXX;
class XMLErrorHandler extends DefaultHandler {
String tagName = "";
String tagValue = "";
String applicationRefNo = "";
String XXXValue ="";
String XXXNo = "";
XMLValidator objXmlValidator = new XMLValidator();
public void startElement(String uri, String name, String qName, Attributes atts) {
tagName = qName;
public void characters(char ch[], int start, int length) {
if ("Reference".equals(tagName)) {
tagValue = new String(ch, start, length).trim();
if (tagValue.length() > 0) {
RefNo = new String(ch, start, length);
if ("XXX".equals(tagName)) {
XXXValue = new String(ch, start, length).trim();
if (XXXValue.length() > 0) {
XXXNo = new String(ch, start, length);
public void endElement(String uri, String localName, String qName) throws SAXException {
if(qName.equalsIgnoreCase("XXX")) {
objXmlValidator.setXXX(XXXNo);
thnx & Regards,
ritu -
Create xml from xml schema in java
If can i create a xml document framework from xml schema in java, then i can fill the value in java?
thanksAn XML document may be created from an XML Schema with JAXB.
Maybe you are looking for
-
How do I change my email account on my mac from Mail to Icloud?
Does anyone know how to change my mail account on my mac to I cloud? since i have changed to Icloud on my iphone it seems that I can't access the old mailserver anymore. What do I do? Thanks for any advise Alex
-
Using ref cursor in "in clause" in select statement
Hi, Is there any way can we use the ref cursor in the in condition of a select statement. Regards, Venkat. Edited by: ramanamadhav on Aug 23, 2011 11:14 AM
-
I use my wife's apple id for all my devices. i have a mac book, ipad and 2 iphones. i am wanting to have seperate id's but still share things between devices. how do i go about setting this up without deleting anything?
-
User Profile Services start in all sharepoint servers in farm
Hi, Do we need to start the below services in all sharepoint servers in farm? 1) User Profile Service 2) User Profile Synchronization Service Thanks....
-
Hi together, My challenge is to start an OWB workflow from an apex procedure. Procedure: declare numb number; audit_id number; begin numb := rtruser_blueprint.exec_api.execute('LOC_A014_OWF_MGR', 'PROCESS', 'LOAD_CALM_DELIVERY', ',', 'DELIVERY_ID_IN=