user7084787 user7084787 - 1 year ago 86
iOS Question

I am not able to parse IOS driver page source

I got Page source using

String pageSource = driver.getPageSource();

Now i need to save this xml file to local in cache. So i need to get element attributes like x and y attribute value rather than every time get using
. But I am not able to parse pageSource xml file to some special character. I cannot remove this character because at if i need element value/text it shows different text if i will remove special character. Appium is use same way to do this.

Answer Source

I was also facing same issue and i got resolution using below code which i have written and it works fine

public static void removeEscapeCharacter(File xmlFile) {

    String pattern = "(\\\"([^=])*\\\")";
    String contentBuilder = null;
    try {
        contentBuilder = Files.toString(xmlFile, Charsets.UTF_8);
    } catch (IOException e1) {
    if (contentBuilder == null)
    Pattern pattern2 = Pattern.compile(pattern);
    Matcher matcher = pattern2.matcher(contentBuilder);
    StrBuilder sb = new StrBuilder(contentBuilder);

    while (matcher.find()) {

        String str =, - 1);
        try {
            sb = sb.replaceFirst(StrMatcher.stringMatcher(str),
        } catch (Exception e) {

    try {
        Writer output = null;
        output = new BufferedWriter(new FileWriter(xmlFile, false));


    } catch (IOException e) {

if you will get that kind of problem then catch it with remove special character and parse again.

    try {
            doc = db.parse(fileContent);
        } catch (Exception e) {

            doc = db.parse(file);

It might works for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download