Ignore:
Timestamp:
2013-09-13T17:02:24+12:00 (11 years ago)
Author:
sjm84
Message:

Trying a new method for printing XML

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r28179 r28283  
    9292    public static final String INDEX_STEM_ELEM = "indexStem";
    9393    public static final String INDEX_OPTION_ELEM = "indexOption";
    94   public static final String PARAM_DEFAULT_ELEM = "paramDefault";
     94    public static final String PARAM_DEFAULT_ELEM = "paramDefault";
    9595    public static final String BROWSE_ELEM = "browse";
    9696    public static final String DISPLAY_ELEM = "display";
     
    13411341            }
    13421342        }
    1343         NodeList children = e.getChildNodes();
    1344 
     1343
     1344        if (e.hasChildNodes())
     1345        {
     1346            boolean hasElements = false;
     1347            boolean indentSwapped = false;
     1348
     1349            Node child = e.getFirstChild();
     1350            do
     1351            {
     1352                if (child.getNodeType() == Node.ELEMENT_NODE)
     1353                {
     1354                    hasElements = true;
     1355                }
     1356                if (child.getNodeType() == Node.TEXT_NODE && indent)
     1357                {
     1358                    if (child.getNodeValue() != null && child.getNodeValue().trim().length() > 0)
     1359                    {
     1360                        indentSwapped = true;
     1361                        indent = false;
     1362                    }
     1363                }
     1364            } while ((child = child.getNextSibling()) != null);
     1365
     1366            sb.append(">");
     1367            if (hasElements && indent)
     1368            {
     1369                sb.append("\n");
     1370            }
     1371
     1372            child = e.getFirstChild();
     1373            do
     1374            {
     1375                xmlNodeToString(sb, child, indent, indentString, depth + 1);
     1376            } while ((child = child.getNextSibling()) != null);
     1377
     1378            if (indent)
     1379            {
     1380                for (int i = 0; i < depth; i++)
     1381                {
     1382                    sb.append(indentString);
     1383                }
     1384            }
     1385
     1386            sb.append("</" + e.getNodeName() + ">");
     1387
     1388            if ((hasElements && indent) || indentSwapped)
     1389            {
     1390                sb.append("\n");
     1391            }
     1392        }
     1393        else
     1394        {
     1395            sb.append("/>");
     1396
     1397            if (indent)
     1398            {
     1399                sb.append("\n");
     1400            }
     1401        }
     1402
     1403        /*
    13451404        boolean hasElements = false;
    13461405        boolean indentSwapped = false;
     
    13991458            }
    14001459        }
     1460        */
    14011461    }
    14021462
Note: See TracChangeset for help on using the changeset viewer.