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 find not-empty tags inside a string and returns a list with all tags.

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

      Note: To fine also empty tags use 'findTags'

      Parameters:
      content - - XML data
      tag - - XML tag
      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