Module jEdit

Class XMLUtilities

java.lang.Object
org.gjt.sp.util.XMLUtilities

public class XMLUtilities extends Object
XML utility methods that only depend on the JDK.
Since:
4.3pre6
Version:
$Id: XMLUtilities.java 24859 2018-04-10 23:06:33Z daleanson $
Author:
Marcelo Vanzin
  • Method Details

    • charsToEntities

      public static String charsToEntities(String str, boolean xml11)
      Converts <, >, & in the string to their HTML entity equivalents.

      If xml11 is true, then character entities are used to convert illegal XML characters (mainly ASCII control characters).

      Parameters:
      str - The string
      xml11 - Whether to allow XML 1.1 constructs.
    • parseXML

      public static boolean parseXML(InputStream in, DefaultHandler handler) throws IOException
      Convenience method for parsing an XML file. This method will wrap the resource in an InputSource and set the source's systemId to "jedit.jar" (so the source should be able to handle any external entities by itself).

      SAX Errors are caught and are not propagated to the caller; instead, an error message is printed to jEdit's activity log. So, if you need custom error handling, do not use this method.

      The given stream is closed before the method returns, regardless whether there were errors or not.

      Returns:
      true if any error occured during parsing, false if success.
      Throws:
      IOException
    • findEntity

      public static InputSource findEntity(String systemId, String test, Class<?> where)
      Tries to find the given systemId in the context of the given class. If the given systemId ends with the given test string, then try to load a resource using the Class's getResourceAsStream() method using the test string as the resource.

      This is used a lot internally while parsing XML files used by jEdit, but anyone is free to use the method if it sounds usable.