I have a currency converter application for iphone which uses web service. The web service is returning result in the following format:-
<Date>4/5/2010</Date>
<Time>7:18:09 AM</Time>
<Amount>20</Amount>
<ExchangeRate>44.7336419443466</ExchangeRate>
<Result>894.672839</Result>
I'm storing the whole xml file in an NSString variable called theXML. I want to show the value inside the result tag.How can i read the data from the xml file or from the string..
Thanks in advance..
Use XPath.
Related
I am learning Camel Integration with Springboot. I was trying to get the json response from restapi and then want to store the data into some file.
Below is the route class component which I created . It is not able to convert the json response into filestream type. Can anyone tell me what am I doing wrong here.
rest().get("/orders").produces(MediaType.APPLICATION_JSON_VALUE).route().
setBody(()-> orderService.getOrders()).to("direct:transferToFile").endRest();
from("direct:transferToFile").convertBodyTo(Order.class).to("file:output?fileName=getOrders.txt");
You cannot write an Order object into a file. You need to marshal it into json before writing it to the file.
You can add a marshal().json(JsonLibrary.Jackson) after the convertBodyTo.
I am trying to create an array of objects within the Parse Data Browser, in my web browser. I was wondering how I would go about doing this?
Thanks
Looks like each Pointer is just a dictionary structure so the following works:
[{"__type":"Pointer","className":"yourClassName","objectId":"yourObjectsId"},
{"__type":"Pointer","className":"yourClassName","objectId":"your2ndObjectsId"}]
I have added a regular expression as below in order to extract the response value inside the xml.
p400="http://newman.services.premium.hellocorp.com">(.+?)</p400:newman></soapenv:Body>
the reference name is "output_xml"
I have added a simple data writer as well and added "output_xml" to the sample variables in Jmeter properties file also. Still I am not able to see the xml getting written in the file.
Please advice me on this. Thanks!
I'm not sure, that it's possible with simple file writer, try FlexibleFileWriter plugin http://jmeter-plugins.org/wiki/FlexibleFileWriter/?utm_source=jpgc&utm_medium=link&utm_campaign=FlexibleFileWriter
And have you checked, that this extractor works on your data?
Try to add Debug Postprocessor (ensure that "JMeter variables" is set true) and View Results Tree elements to you project and inspect variables.
The given xml formats
p400="http://newman.services.premium.hellocorp.com">(.+?)</p400:newman></soapenv:Body>
You need to update the following regex formats to extract the response values
Regular expression formats
http://newman.services.premium.hellocorp.com">(.+)</p
AM developing a auto completion or suggestion box using AJAX and servlets . My problem is how to parse the XML response in java script to show it in a div tag.My xml response is like contains one parent tag RESULTS , it contains number of children tags called RESULT.
How to get result values in java script variables.
You could do this using jQuery.parseXML
Take look on this thread: Parse XML from XMLHttpRequest
I think it contains information you need.
I'm using Spring 3 ability to upload a file. I would like to know the best way to validate that a file is of a certain type, specifically a csv file. I'm rather sure that checking the extension is useless and currently I am checking the content type of the file that is uploaded. I just ensure that it is of type "text/csv". And just to clarify this is a file uploaded by the client meaning I have no control of its origins.
I'm curious how Spring/the browser determines what the content type is? Is this the best/safest way to determine what kind of file has been uploaded? Can I ever be 100% certain?
UPDATE: Again I'm not wondering how to determine what the content type is of a file but how the content type gets determined. How does spring/the browser know that the content type is a "text/csv" based on the file uploaded?
You can use
org.springframework.web.multipart.commons.CommonsMultipartFile object.
it hasgetContentType(); method.
Look at the following example http://www.ioncannon.net/programming/975/spring-3-file-upload-example/
you can just add the simple test on CommonsMultipartFile object and redirect to error page if it the content type is incorrect.
So you can also count the number of commas in the file per line.There should normally be the same amount of commas on each line of the file for it to be a valid CSV file.
Why you don't just take the file name in you validator and split it, the file type is fileName.split("\.")[filename.length()-1] string
Ok, in this case i suggest you to use the Csvreader java library. You just have to check your csvreader object and that's all.
As far as I'm aware the getContentType(String) method gets its value from whatever the user agent tells it - so you're right to be wary as this can easily be spoofed.
For binary files you could check the magic number or use a library, such as mime-util or jMimeMagic. There's also Files.probeContentType(String) since Java 7 but it only works with files on disk and bugs have been reported on some OSes.