Newlines/Non-printable characters are visible
I am using gradle to download a localise.biz Android localization.
I am parsing the resulting XML with groovy.util.XMLParser
.
I want to write the content of a particular node into a separate file, because it contains HTML and Android does not allow storing too long strings in regular resource files.
When I extract the HTML and display it in Android, \n
and unicode control blocks such as \u0020
are visible. What am I missing here?
// parsing android strings resource file and extract privacy policy html document
def resources = new XmlParser().parse(new File(buildDir,s[1]))
def privacyPolicyNode = resources.find { node ->
(node.attribute("name") == "privacy_policy_txt")
}
def fileForPrivacyPolicy = new File(buildDir,s[2])
if(!fileForPrivacyPolicy.exists()) {
fileForPrivacyPolicy.parentFile.mkdirs()
fileForPrivacyPolicy.createNewFile()
}
def localizedString = privacyPolicyNode.text()
println localizedString
def writer = new BufferedWriter(new FileWriter(new File(buildDir,s[2])))
writer.write(localizedString)
writer.flush()
The particular string entry looks like this : https://pastebin.com/0538E3f8
And I am loading the HTML like this:
val htmlString = resources.openRawResource(R.raw.privacy_policy).bufferedReader().readText()
webView.loadData(htmlString,"text/html","UTF-8")
do you know?
how many words do you know
See also questions close to this topic
-
Updating a Single Column In Room Database
That's the function I'm using for updat
private fun updateSettingsDatabase(settingsDao: SettingsDao) { lifecycleScope.launch { settingsDao.update(SettingsEntity( 1, nightMode=nightModeResult, )) } } @Query("SELECT * FROM `settings-table`") fun fetchCurrentSettings(): Flow<List<SettingsEntity>>
I specified
nightMode=
because I thought that this way I'm only updating this colummn, but it turns out that it resets every column, how do I update a single column, while keeping the values the rest of the columns? -
Using EdittextPreference for Goto search
sorry for my poor English. I want to use EditTextPreference in my bottom nav like the pic below, ![screenshot][1]
I have recycleview xml in my project with in many sub cardview layouts(which is scrollable) and I want to create item in the bottom nav which is called "Goto". When the "Goto" item is clicked i want it to pop-up like the screenshot. And when user enters a number(according to the cardviews i.e if the number of cardview is 40 user must enter 1-40) I want to search the cardview by its ID. Thank you and I hope u got it, If u have any questions let me know [1]: https://i.stack.imgur.com/grK8P.jpg
My xml format look like this. As you see in the blow since the cardviews are huge in number it is not cool to scroll all the way down that is why i need Goto item in the bottom nav to search it by its ID when the user click number in the EditTextPreference as u see in the screenshot. i.e The screenshot is not from my app
<LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> .. .. .. .. many more..
-
IOS Launcher in android studio
I'm trying to change the whole Android OS installed app icons into IOS icons, please help me with the proper code or library for android kotlin
-
Java - Update Elements in Large XML Files
I work with very large XML datasets (1 GB+) and need to backtrack and update specific elements per node, depending on the values of other elements that follow.
For example, in this record/node:
<user> <role>Associate</role> <team>Hufflepuff</team> <experience>7</experience> </user>
Since "experience" is greater than 5 years, the role needs to be updated from "Associate" to "Senior."
I would like to avoid loading the entire file into memory via the DOM.
Ideally, I would process each single "user" in the XML and append the data to a new XML file one at a time. I started off by processing in a stream using StAX, but I don't know how to transform each XMLEventWriter event content into a useable DOM document that writes to an XML file and clears from memory afterwards.
If the description is unclear in any way, please let me know. Any help on this will be greatly appreciated.
Thanks.
-
cant read field in xml section
Using python I got to the correct iteration of the XML (forecast) section, but one child field I cant seem to be able to read here is the section from the XML
<forecast> <fcst_time_from>2022-05-04T16:00:00Z</fcst_time_from> <fcst_time_to>2022-05-04T20:00:00Z</fcst_time_to> <change_indicator>FM</change_indicator> <wind_dir_degrees>110</wind_dir_degrees> <wind_speed_kt>6</wind_speed_kt> <visibility_statute_mi>6.21</visibility_statute_mi> <sky_condition sky_cover="SCT" cloud_base_ft_agl="4500"/> <sky_condition sky_cover="SCT" cloud_base_ft_agl="25000"/> </forecast>
I can get every field except
<sky_condition sky_cover="SCT" cloud_base_ft_agl="25000"/>
here is the code where I pull the fields
if startTime_new <= Cur_Date_UTC <= EndTime_new: #Cil2 = (l.find('sky_cover')).text wDir = (l.find('wind_dir_degrees')).text wSpd = (l.find('wind_speed_kt')).text vis = (l.find('visibility_statute_mi')).text Cil = (l.find('sky_condition')).text print(wDir) print(wSpd) print(vis) print(Cil) print(l)
The answer given did work in a comand window but I am using beautifulsoup to get the XML . I tried to import from datetime import datetime however Cil = [x.get('sky_cover') for x in elt.findall('sky_condition')] did not work
here is my full code
from bs4 import BeautifulSoup as bs import requests import pytz from datetime import datetime #pirip=False def SetDateTimes(): utc_time = datetime.now(pytz.utc) Cur_Date_UTC = utc_time.strftime("%d/%m/%y %H:%M:%S") return Cur_Date_UTC def FixDateTime(workingTime): workingTime = workingTime.replace('T', ' ') workingTime = workingTime.replace('Z', '') format = "%Y-%m-%d %H:%M:%S" dt_object = datetime.strptime(workingTime, format) day_st = dt_object.strftime("%d") month_st = dt_object.strftime("%m") year_st = dt_object.strftime("%y") time_st = dt_object.strftime("%H:%M:%S") workingTime = day_st + '/' + month_st + '/' + year_st + ' ' + time_st return workingTime def GetTAF3(): USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36" url = 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=tafs&requestType=retrieve&format=xml&hoursBeforeNow=3&timeType=issue&mostRecent=true&stationString=KEWR' session = requests.Session() session.headers['User-Agent'] = USER_AGENT html = session.get(url) soup = bs(html.text, 'html.parser') taf = soup.find_all("forecast") for l in soup.findAll('forecast'): startTime = l.find('fcst_time_from').text EndTime = (l.find('fcst_time_to')).text #print(startTime) startTime_new = FixDateTime(startTime) #print(startTime_new) #print(EndTime) EndTime_new = FixDateTime(EndTime) #print(EndTime_new) #break if startTime_new <= Cur_Date_UTC <= EndTime_new: #Cil2 = (l.find('sky_cover')).text print(l) wDir = (l.find('wind_dir_degrees')).text wSpd = (l.find('wind_speed_kt')).text vis = (l.find('visibility_statute_mi')).text Cil = (l.find('sky_condition')) print(wDir) print(wSpd) print(vis) print(Cil) print(l) if 'OVC' in Cil: print("OVC Found") pirip = True else: print('No PIRIP') if float(vis) < 5: print("pirip for vis") pirip = True else: print('No PIRIP') Cur_Date_UTC = SetDateTimes() GetTAF3() #print(pirip)
-
How can I use Continue in a choose statement in xslt
I want to continue to check for other if statements if the first one is met. From what I read, Choose statement does not have this functionality like other languages do. One post suggested to just run multiple if statements but this is not working. After the first if statement is met it stops there, I want it to keep running.
How can I achieve this? This is my code:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" omit-xml-declaration="yes"/> <xsl:template match="root"> { "entityList": [ <xsl:for-each select="//entityList"> { "notes":"<xsl:call-template name="replace"> <xsl:with-param name="text" select="./Notes"/> </xsl:call-template>", } <xsl:if test="position() != last()">,</xsl:if> </xsl:for-each> ] } </xsl:template> <xsl:template name="replace"> <xsl:param name="text"/> <xsl:param name="searchString">"</xsl:param> <xsl:param name="replaceString">\"</xsl:param> <xsl:param name="searchStringSpace">	</xsl:param> <xsl:param name="searchStringBackslash">\</xsl:param> <xsl:if test="contains($text,$searchString)"> <xsl:value-of select="replace(./Notes,'"','\\"')"/> </xsl:if> <xsl:if test="contains($text,$searchStringSpace)"> <xsl:value-of select="replace(./Notes,'	','\\t')"/> </xsl:if> </xsl:template> </xsl:stylesheet>
<root> <totalRecords>429</totalRecords> <offset>0</offset> <entityList> <Notes>Dear Deans, Chairs and "Directors,There was a 	ANDOR question about scheduling Mac Hall Auditorium,for regular classes and policy/procedure around it.,Mac Hall Auditorium was intended to be available as a,regular classroom. That is why the seats have built-in mini,desks.,Your programs are welcome to schedule classes in,Mac Auditorium - you can request it when submitting your,course schedules for the Semester or through the Schedule,Change Request Form.,There are, however, some conditions:,1)faculty members who teach in Mac Auditorium should,anticipate that their class may be displaced if the,University-wide function (president?s address, a conference,,etc.) is scheduled at the time of their class. It would be,up to the faculty to either reschedule that,class meeting for a different time, find another room/space,or substitute the class meeting with an alternative activity,There is no easy way to inform faculty about the upcoming,events, so they would have to watch University Calendar to,determine when their classes might be affected.,2)Mac Hall will be unavailable for scheduling regular,courses during evening hours (6-10 pm) ? that time will be,set aside for Pegasus Players practices.,Natalia F. Blank, Ph.D. 2/17/21</Notes> </entityList> <totalPages>1</totalPages> <page>0</page> <status>success</status> </root>
-
Kotlin Coroutines Unit Testing
Im trying to test this suspend function:
suspend fun <T> getResult(call: suspend () -> Response<T>): Resource<T> { val response = call() val body = response.body() val code = response.code() if (response.isSuccessful) { Log.d(Cybrid.instance.tag, "Data: ${response.code()} - ${response.body()}") return Resource.success(body!!, code) } else if (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) { Cybrid.instance.let { cybrid -> cybrid.listener.let { cybrid.invalidToken = true it?.onTokenExpired() } } Log.e(Cybrid.instance.tag, "Error - Something wrong with TOKEN : ${response.code()} ${response.message()}") return Resource.error(response.message(), code=response.code()) } else { Log.e(Cybrid.instance.tag, "Error - Other: ${response.code()} ${response.message()} :: ${response.raw()}") return Resource.error(message = response.message(), data= response.body(), code= response.code()) } }
With this Unit Test Case, all it cover except line 13 , I dont know how to cover the line!!!
@ExperimentalCoroutinesApi @Test fun get400ErrorServerTest() = runBlocking { Cybrid.instance.setBearer("Bearer") val pricesService = AppModule.getClient().createService(PricesApi::class.java) val result = getResult { pricesService.listPrices() } Assert.assertNotNull(result) Assert.assertEquals(result.code, 400) Assert.assertNull(result.data) }
The coverage report says:
Some idea to get coverage for line 13 ??? Thnanks
-
Android ZoneDateTime.withHour always sets hour to 8
So I am tring to schedule alarm at a particular time on current day using AlarmManager. To do that I am using ZoneDateTime to get current time and then updating it to the hour at which I need to set the alarm. But for some reason time.withHour is giving me 8pm or 8am no matter what hour I am passing to it. Am I doing something wrong here?
var time = ZonedDateTime.now() //getting current time at my timezone time = time.withHour(22).withMinute(8).withSecond(0) print(time) //getting 8am/8pm at my timezone val timeMilis = time.toInstant().toEpochMilli()
-
how to change gradle version in nativescript
I'm confused as how to change a specific configuration somewhere to determine the version of my gradle, in a nativescript project. My workspace is created with nx and when I try to run the app with
npx nx run test:android
I get this error message:Could not compile settings file '<somepath>\start\learn\apps\nativescript-test\platforms\android\settings.gradle'. > startup failed: General error during conversion: Unsupported class file major version 62
Based on my research if I need to resolve this issue I need to either update my gradle version or downgrade my JDK version. The solution I'm searching for is to how to specify my gradle version. Thanks in advance.
-
Why are Gradle projects so huge?
As a long time Maven user I thought I'd try creating an IntelliJ plugin using their preferred build tool Gradle, and the moment I had their template (as recommended by IntelliJ here) cloned to my local machine I tried to build and run the plugin but it took forever.... just like all my past encounters with Gradle.
Then I noticed the size of the project had exploded to almost 4GB!... 🤔
How is this possible?
-
msvcrtd.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function
I am using gradle to build my c++ library
I added this line to build.gradle file
linkTask.linkerArgs.add("msvcrt${linkTask.name.toLowerCase().contains('debug') ? 'd' : ''}.lib")
Error :
> Task :psfe:linkDebugWindows FAILED msvcrtd.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) Caching disabled for task ':psfe:linkDebugWindows' because: D:\a\piv\piv\psfe\build\lib\main\debug\windows\psfe.dll : fatal error LNK1120: 1 unresolved externals Build cache is disabled
How can I solve this error ?