Same xml | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Same xml

I have a lot of layout and all of them are same but the text in each of them is different. How can i make them less with different data

23rd Dec 2016, 11:59 AM
amin ahrami
amin ahrami - avatar
3 Answers
+ 2
You can serve them dynamically: like your php ( or other server side language ) for serve html, you can serve whatever file, especially if it's text... and fill you template with your differents data... Think to adapt the http header for handling xml ^^
23rd Dec 2016, 12:11 PM
visph
visph - avatar
+ 2
I had not notice, you've put "java" and "android" in the question tag, and my responce was about if you use your xml files for web... So, in an android app, you can too communicate with a server to retrieve you xml files, but maybe you want locally get/generate them? You can relatively easyly make a layout system with string remplacement functions... For example, magine you've this model: <song title='music 1'> <singer name='toto'/> <composer name='muse is cyan'/> </song> Only the texts in quotes will change... so, write a layout with fake values, which can be safely search and find, like: <song title='&&SONG&&'> <singer name='&&SINGER&&'/> <composer name='&&COMPOSER&&'/> </song> In a file or a variable literal assignation, according to your needs: load it in a variable ( if stored in a file ) for use, and search/replace the custom identifiers with your data values, stored separately ( retrieve them from a database probably, but can be in a file, or inlined -- literal assignation ). With a simplified example from previously: String my_data="For he's a jolly good fellow"; String my_layout="<song title='&&SONG&&'></song>"; String my_xml=my_layout.replace("&&SONG&&",my_data); And in "my_xml" variable you get: <song title='For he's a jolly good fellow'> For more advanced search/find/replace functions, look at RegEx and replaceFirst and replaceAll functions ( which handle RegEx, powerfull cross-language string management )...
28th Dec 2016, 7:47 PM
visph
visph - avatar
0
may you clarify :)
28th Dec 2016, 6:36 PM
amin ahrami
amin ahrami - avatar