I have another important problem, it seems to be more difficult, I hope you can help me. I haven't found a solution yet In the file testxml.txt. We call them strings - they are separated by <>. i want to filter in those strings 2 values:--- text="any character" and bounds="[number][number]"---
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node index="0" text="" resource-id="" package="com.facebook.katana" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,2076]"><node index="0" text="Create account" resource-id="com.facebook.katana:id/(name removed)" package="com.facebook.katana" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[168,108][533,264]" /></node></hierarchy>UI hierchary dumped to: /dev/tty//
The expected output is 1 file output.txt which contains
text=""|bounds="[0,0][1080,2076]"
text="Create account"|bounds="[168,108][533,264]"
....
text=""|bounds="[][]"
CodePudding user response:
Ok. First, you must process your file with a huge line into shorter lines via the solution posted at this answer, that create the fields.txt
file.
After that, run this Batch file:
@echo off
setlocal EnableDelayedExpansion
rem Create a "NewLine" value
for %%n in (^"^
%Do NOT remove this line%
^") do (
rem Process fields.txt file
(for /F "delims=" %%a in (fields.txt) do (
set "field=%%a"
rem Remove closing ">"
set "field=!field:~0,-1!"
rem Split field into lines ending in quote-space
for /F "delims=" %%b in (^"!field:" ="%%~n!^") do echo %%b
)) > lines.txt
)
rem Process lines
set "data="
for /F "skip=2 delims=" %%a in (lines.txt) do (
set "tag=%%a"
if "!tag:~0,5!" equ "<node" (
rem Start of new node: show data of previous one, if any
if defined data (
echo text=!text!^|bounds=!bounds!
)
rem Define the data in the same line of "<node"
set !tag:* =!
set "data=1"
) else if "!tag:~0,6!" equ "</node" (
rem Show data of last node
echo text=!text!^|bounds=!bounds!
) else (
rem Define data
2> NUL set %%a
)
)
Output sample:
text=""|bounds="[0,0][1080,2076]"
text=""|bounds="[0,0][1080,2076]"
text=""|bounds="[0,108][1080,2076]"
text=""|bounds="[0,108][1080,2076]"
text=""|bounds="[0,108][1080,276]"
text=""|bounds="[0,108][168,276]"
CodePudding user response:
Assuming file.xml is this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<hierarchy rotation="0">
<node index="0" text="" resource-id="" package="com.facebook.katana" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,2076]" />
<node index="0" text="Create account" resource-id="com.facebook.katana:id/(name removed)" package="com.facebook.katana" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[168,108][533,264]" />
</hierarchy>
Do
[xml]$xml = get-content file.xml
$xml.hierarchy.node | select text,bounds
text bounds
---- ------
[0,0][1080,2076]
Create account [168,108][533,264]
CodePudding user response:
@Aacini . This is the content of the file lines.txt
<?xml version='1.0' encoding='UTF-8' standalone='yes'
<hierarchy rotation="0
<node index="0
text="
resource-id="
com.facebook.katana
content-desc="
checkable="false
checked="false
clickable="false
enabled="true
focusable="false
focused="false
scrollable="false
long-clickable="false
password="false
selected="false
bounds="[0,0][1080,2076]