Class XMLParser

java.lang.Object
org.imixs.workflow.util.XMLParser

public class XMLParser extends Object
XMLParser provides helper methods to parse xml strings
Author:
rsoika
  • Constructor Details

    • XMLParser

      public XMLParser()
  • Method Details

    • findAttributes

      public static Map<String,String> findAttributes(String content)
      This method parses a xml tag for attributes. The method returns a Map with all attributes found in the content string e.g. returns Map: {field=a, number=1}
      Parameters:
      content -
      Returns:
    • findAttribute

      public static String findAttribute(String content, String name)
      This method parses a xml tag for a single named attribute. The method returns the value of the attribute found in the content string e.g. returns "abc"
      Parameters:
      content -
      Returns:
    • findTags

      public static List<String> findTags(String content, String tag)
      This method find specific tags inside a string and returns a list with all tags.

      e.g. an empty tag:

      <date field="abc" />

      or a tag with content:

      <date field="abc">def</date>

      Note: In case of complex XML with not empty tags use the method 'findNoEmptyTags'

      Parameters:
      content - - XML data
      tag - - XML tag
      Returns:
    • findNoEmptyTags

      public static List<String> findNoEmptyTags(String content, String tag)
      This method finds no-empty tags by name inside a string and returns a list with all tags including the tag itself.

      e.g.: <date field="abc">def</date>

      Note: To find also empty tags use 'findTags'

      Parameters:
      content - - XML data
      tag - - XML tag
      Returns:
    • findNoEmptyXMLTags

      public static List<String> findNoEmptyXMLTags(String content, String tag)
      This method finds no-empty tags by name inside a string and returns the embedded XML content. The method returns a list of xml tags including the tag itself.

      e.g.: <date field="abc">def</date>

      Note: To find also empty tags use 'findTags'

      Parameters:
      content - - XML data
      tag - - XML tag
      Returns:
    • isXMLContent

      public static boolean isXMLContent(String content)
      Test if a given String is XML Content
      Parameters:
      content -
      Returns:
    • findTagValues

      public static List<String> findTagValues(String content, String tag)
      This method returns all tag values within a string with multiple xml tags. E.g.

      <date>2016-12-31</date>...<date>2016-11-30</date>

      returns

      2016-12-31|2016-12-31

      Parameters:
      content - - XML data
      tag - - XML tag
      Returns:
    • findTagValue

      public static String findTagValue(String content, String tag)
      This method returns the tag value of a single tag. The method returns the first match! Use findTagValues to parse all tag values in a string with multiple tags.

      E.g.

      <date>2016-12-31</date>...<date>2016-11-30</date>

      returns

      2016-12-31

      Parameters:
      content - - XML data
      tag - - XML tag
      Returns:
      See Also:
    • findTagValueOld

      @Deprecated public static String findTagValueOld(String content, String tag)
      Deprecated.
    • parseItemStructure

      public static ItemCollection parseItemStructure(String xmlContent) throws PluginException
      This method parses the xml content of a item element and returns a new ItemCollection containing all item values. Each tag is evaluated as the item name. MultiValues are currently not supported. Example:
       
       <item>	  
          <modelversion>1.0.0</modelversion>
          <task>1000</task>
          <event>10</event>
       </item>
       
       
      Parameters:
      evalItemCollection -
      Throws:
      PluginException
    • parseTag

      public static ItemCollection parseTag(String xmlContent, String tag) throws PluginException
      This method parses the xml content of a XML tag and returns a new ItemCollection containing all embedded tags. Each tag is evaluated as the item name. The tag value is returned as a item value.

      MultiValues are currently not supported.

      Example:

      The tag 'code' of:

       
       <code>	  
          <modelversion>1.0.0</modelversion>
          <task>1000</task>
          <event>10</event>
       </code>
       
       

      Returns an ItemCollection with 3 items (modelversion, task and event)

      Parameters:
      evalItemCollection -
      Throws:
      PluginException
    • parseTagList

      public static List<ItemCollection> parseTagList(String content, String tag) throws PluginException
      This method parses the xml content and returns a list of ItemCollection elements for each tag with the given tag name

      Example:

      The tag 'code' of:

       
       <code>	  
          <modelversion>1.0.0</modelversion>
          <task>1000</task>
          <event>10</event>
       </code>
       <code>	  
          <modelversion>2.0.0</modelversion>
          <task>2000</task>
          <event>20</event>
       </code>
       
       

      Returns a List with two ItemCollections each with 3 items (modelversion, task and event)

      Parameters:
      evalItemCollection -
      Throws:
      PluginException