Solved

Xpath Parsing Question

Comments: 6 - Last Comment by bcunningham on Aug 20, 2016   Comment Filter:
Posted on Jun 20, 2016
 
 

I am trying to write a system to read the supplemental info for an event and write the records into the event comments. I have not been able to determine how to write the xpath language to check if the field is blank. What I encountering is that if the previous record had a value in a field and the following record had no information in the same field, the previous value is being written into the field for that record and any subsequent record added to the event. I attached a screen shot of the supplemental info screen with an example.

The OLN field for the first record would be written into the OLN field for every following record in the series if the OLN field was empty. My XPath statement for the OLN field is /IFCADCustomReport/Body/Results/Row/oln. I have not able to find a solution searching on line.

Any assistance would be appreciated.

Thanks,

Bruce Cunningham

Gallatin County 911

Bozeman, MT

Point your RSS reader here for a feed of the latest messages in this topic
RE: Xpath Parsing Question
Posted on Jul 11, 2016 in response to: bcunningham
 
   
 

This is an XPath function and so we'll have to work around it. I've attached an example System to show one way of working around this in EF. For some background, this would all be avoided if each XML object (inside of a large XML document) contained the same tags...even if they are EMPTY. In a perfect world, even if a tag didn't have a value, it would still be present in the XML object. Like this:

  • "<tag1></tag1>"; or
  • "<tag1 />"

Instead, sometimes the tags are removed (not present; not empty; simply not included). This will lead to the XPath parsing challenge you mention where the previous row's value for that Field will be included as the value for the current Field (as you mentioned in your post).

The workaround is to use 2 Series. The first Series will parse out all the known, standard tags that should be present for each XML object. The second Series will XPath out the XML snippet (inside of the larger XML object) that deals with the XML in question. We will store this XML snippet into a single Field in EF and then pass it down to a second "child" Series for further processing. In order to parse this out in the second "child" Series, we will need to append a root tags around the snippet to make it a valid XML document in it's own right (since XPath will only work in the second Series if the value being passed down is valid XML with a root tag).

The best way to describe the process is to check out the sample System. It's sort of hard to explain it via a forum post.

Example System Notes:

  • When the System is Loaded, I'm adding a sample XML document to the "Cars" Series. The zip file contains a screenshot of what the XML looks like in a Word doc...can't C/P into these forum windows). You can also see this in the Action Parameter for the "AddRow" Action underneat of the SYSTEM>>LOADED Event.
  • The XML contains 3 Vehicle objects, and each contains a Name, Type, and Attributes tag.
  • Inside the Attributes tag, a Vehicle can have x number of Attributes. Each Attribute is identified by the Attribute tag.
  • In the example, the first 2 vehicles both have Location Attribute tags, but the last Vehicle does not. If you tried to parse this all out in one Series, the last row in the Series, which is associated with the last Vehicle, would actually have a Location value of the previous rows Location, even though it did not have a Location value to begin with. 
  • To get around this we parse out all the known, high-level values (Name, Type) into the first Series, and then create a single Field that will contain all of the Attributes XML for each vehicle. When the row is added to the first Series, we append root tags aroudn the Attributes XML to make it valid XML (so we can do XPath) parsing in the child Series.
  • Each Vehicle makes its own row in the first Series, so each row in the first Series is then passed down to the second, child Series. By doing this, we segregate each Vehicle into its own row so it's processed separately, so if there is no XML Attribute value (i.e. Location) for one of the Vehicles, it will just show up as empty, as opposed to copying the previous rows value.

I could go one, but just check out the attached System and see if you can apply this to your workflow. That is probably the best idea.  

 

Hope this Helps.

-Jack

XPathQuestion_CarsExample.zip

Add a Comment

Please sign in on the right menu to comment.  If you do not have an account, please Join now.