Java XML Parsing into object - java

We have a requirement of parsing xml data in java.
The xml data looks like this:
xml_data
1> The first question here is how to parse such data.I have tried the code suggested in this link :
xmlparse with Node
and have partial success. The only doubt here is how can i can to reach "" tag.
2>The second question is if the data is parsed how can we can store the values in single object,so that we can get length and values of "CRAWL", "Test", "Check"(Tables) separately(from single object)?
Please help me as how can we achieve this?
Abhi

Related

How to convert String to Json Object in java or groovy

I saved a json into the database as a string like this:
"[_district:_1_2_5village, _name:_1_1_2id_inter, _gender:_1_3_5sex]"
Now i want to convert it back to a Json Object so as to pick the key and value eg _district is the key and _1_2_5village is the value. Any help on how i can achieve this. Thanks
I tried to convert the string back into JSON by parsing but that dint work for me.
It doesn't work because that's not a JSON format, a JSON is a way of mapping objects and uses key value syntax like so:
{"key": "value"}
and an array would look like this:
[{"key": "value"},{"key": "value"}]
You'll need to make a custom parser for your syntax
Here's the json specification:
https://www.json.org/json-en.html

How to read json data in java and display particular output from key value pair

I have json file with data
( "date" : "2019-1-2"
"Group" : "xyz"
"Bookname" : "harrypotter"
"Url" : "https:dhdudgussisk"
),
( " date" : " 2015-2-3"
" Group" : "qbc"
"Bookname" : "happy"
"Url" : "https://hdhdjdksksksks"
)
The code has to be in java written in a way such that when I change the input bookname value the output should display its respective url....some one please help me solve this
Lets hope we understood you right, you want to read out of an json
with key-value method.
I think what could help you is knowing how to properly parse an json to java.
How to parse JSON in Java
There is a lot of libraries providing this. You should explore the internet before you asked a question which was answered many times and it is not hard to find a relevant tutorial.
For example, the Jackson library can be used there.
Intro to the Jackson.

Extracting Element Value from jPOS ISO

I am trying to extract a value within an ISO String which I get from a jPOS Structured Data. The string looks like this:
221ThirdPartyBillPayment3125
<ThirdPartyBillPayment>
<BillPaymentRequest>
<ReferenceId>1111111111</ReferenceId>
</BillPaymentRequest>
</ThirdPartyBillPayment>
Is there a way I can get the value "1111111111" of ReferenceId node?
The sample data is a postilion structured data field which uses kind of a TLV (tag length value format).
221ThirdPartyBillPayment3125
<ThirdPartyBillPayment>
<BillPaymentRequest>
<ReferenceId>1111111111</ReferenceId>
</BillPaymentRequest>
221ThirdPartyBillPayment
Here 2 is the length of length (21), 21 is the length of the tag ThirdPartyBillPayment
3125
<ThirdPartyBillPayment>
<BillPaymentRequest>
<ReferenceId>1111111111</ReferenceId>
</BillPaymentRequest>
</ThirdPartyBillPayment>
Here 3 is the length of length (125), 125, is the length of data to follow.
You could write code to get access to xml iteratively for all thats available in structured data and then parse out the xml data within.
Or
You could ask Postilion for the dtd/schema for the xml used in their structured data iso field and use jaxb to access the data.
It will boil down to a name value pair
ThirdPartyBillPayment= <ThirdPartyBillPayment><BillPaymentRequest<ReferenceId>1111111111</ReferenceId></BillPaymentRequest>
</ThirdPartyBillPayment>
You've got some custom data in a mix of some fixed fields and some XML there, so you first need to get the whole field off your ISOMsg, i.e:
String s = m.getString("127.1"); // provided your data comes in field 127.1
Then figure out where the XML starts (in this case, at indexOf('<')), then you need feed that XML in an XML parser (you can use jdom that comes as a jPOS dependency), parse the XML and get the child element ReferenceId.

What can I do with xml duplicate elements with Smooks?

I m doing parse from xml to Java object. Here is the xml example:
<weather_data>
<date>today</date>
<weather>shower</weather>
<date>tomorrow</date>
<weather>snow</weather>
</weather_data>
That is to say, there are same elements like date and weather inside one weather_data
if I use createOnElement="weather_data/date", I can only get the last date value.
What should I do.
Thanks

How to write a http get request when a key's value is an array?

I have written a java servlet to deal with http get request.I know ,the common format of get request is like this:http://IP_ADDRESS:8080/test?name="jack"&value="shit.
But now ,I have a list of values to transfer,such as an user id list[1,2,3,4].So ,my question is ,how should I write my http get request to express this?And in java servets doGet(),can I use request.getParameterValues to get such an array?
if you are using GET method your url should be looking like that :
http://IP_ADDRESS:8080/test?list=1&list=2&list=3
for retrieving it:
String[] arrlist=request.getParameterValues('list');
your array will be filled with separated values:
//["1","2","3"]
UPDATE : if to write it list[] or list?
when you retrieving your list parameters it wouldn't be parsed as array but as a series of String which will be grouped later on into an array.
Which means even if you write it list[]=1&list[]=2&list[]=3, list[=1&list[=2&list[=3, list*=1&list*=2&list*=3 or list=1&list=2&list=3 it would always be giving you the same answer whether you retrieve it as
request.getParameterValues('list[]') //["1","2","3"]
request.getParameterValues('list[') //["1","2","3"]
request.getParameterValues('list*') //["1","2","3"]
request.getParameterValues('list') //["1","2","3"]
While ,the http request format should be like this:localhost:8080/test?list[]=1&list[]=2&list[]=3
Maybe too simple, but what about repeat parameters name?
http://IP_ADDRESS:8080/test?userId=1&userId=2&userId=3

Categories