how to store XML if i want to change its values in my service?

hey guys. in my service want to use XML. in the service Id change needed values of my XML tags. how can i do that? i was thinking about storing the XMLsomewhere, and then 'importing'/using it in my service methods. how can i do that? thanks
28 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader10mo ago
You could deserialize the xml into java-beans using jaxb.
i hate SQL so much its unreal
but if i want to update the tag values, do i really need to deserialize from XML? e.g. i have <IBAN>123</IBAN>, and would like to have <IBAN>1234</IBAN>
Peter Rader
Peter Rader10mo ago
You do not need beans for that. You could use jsoup having this code: JSoup.parse(xml).select("IBAN").setText(1234);
i hate SQL so much its unreal
oh wow! thats very awesome thing. but i was wondering what are the negative sides of it? bc using jackson/jaxb thing, having pojo for the xml is more or less the standard approach (as i understand)
Peter Rader
Peter Rader10mo ago
Well, you need a little experience about css-selectors. Plain backend-developers might never heard of css-selectors. Using the plain jaxb approach you are byte-true. JSoup does not support byte-trueness.
tjoener
tjoener10mo ago
Jsoup for xml... Have to remember that 👍
i hate SQL so much its unreal
can you rephrase? im not using selectors on my xml file
Peter Rader
Peter Rader10mo ago
I am using a css-selector in JSoup.parse(xml).select("IBAN").setText(1234);
i hate SQL so much its unreal
im trying to do how you showed me, but i dont have setText method
No description
Peter Rader
Peter Rader10mo ago
Ok, my fault. Try : JSoup.parse(xml).select("IBAN").get(0).setText(1234);
i hate SQL so much its unreal
crap 😦
No description
Peter Rader
Peter Rader10mo ago
Try Soup.parse(xml).select("IBAN").get(0).text("1234");
i hate SQL so much its unreal
or maybe this one?
No description
Peter Rader
Peter Rader10mo ago
No. Soup.parse(xml).select("IBAN").get(0).text("1234");
i hate SQL so much its unreal
seems fine
No description
i hate SQL so much its unreal
ill test it in a couple of mins but it changes the value and thats it? i dont need to export or smth like that?
Peter Rader
Peter Rader10mo ago
The contents in the file remains unchanged.
i hate SQL so much its unreal
oh. how do i save the changes?
Peter Rader
Peter Rader10mo ago
Try
var soup = Jsoup.parse(xml);
soup.select("IBAN").get(0).text("1234");
System.out.println(soup);
var soup = Jsoup.parse(xml);
soup.select("IBAN").get(0).text("1234");
System.out.println(soup);
How to read/write file contents is a different thing from this question. You could ask a second question how to save the xml to a file.
i hate SQL so much its unreal
ok. i get
<iban>
123
</iban>
<iban>
123
</iban>
but for some reason its iban, not IBAN
Peter Rader
Peter Rader10mo ago
What is the filename in the variable xml?
i hate SQL so much its unreal
File xml=new File("src/main/resources/accountStatementRequestBody.xml"); Document parsedXml=Jsoup.parse(xml); System.out.println(parsedXml.select("IBAN").get(0).text("123"));
Peter Rader
Peter Rader10mo ago
You print only the iban-node. Dont you like to print the whole xml?
i hate SQL so much its unreal
yeah. but i see that iban node is not in capitals, i get worried lol
Peter Rader
Peter Rader10mo ago
CSS itself is not case-sensitive.
i hate SQL so much its unreal
ive tried googling but i cant find how to save contents to an xml file
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?