Skip to main content

how can i extract the attributes [Equipment-ID, Cleint-ID, Height and Date] from this xml? Any help will be highly appreciated.

 

Kind regards,

Keller.

If the XML is well formatted you could use an XMLFragmenter with "Elements to Match" = Data.

 

image 

And then a XMLFlattener with Elements to Match = Equipment-ID, Cleint-ID, Height and Date. You will need to expose those attributes in the Attributes to Expose, too.

 

image 

PS: For some reason, the XML you have posted can't be properly parsed in my Notepad++. That could be an issue with my Notepad++ or an issue of the SOAP service you are using.


Hello @oscard​ many thanks for the answer, i have tried flattening and exposing based on tutorials on the same topic but i get no data, here is the same xml using notepad+++

 

Thanks,

Keller.


Hello @oscard​ many thanks for the answer, i have tried flattening and exposing based on tutorials on the same topic but i get no data, here is the same xml using notepad+++

 

Thanks,

Keller.

There is an encoding issue with that XML. I guess the first step should be solving that and then try to extract data.

 

Let me see if I can think of something or maybe someone else knows how to tackle this problem.

 

The XML should look like this:

 

 


This issue is more complex than I was expecting and it's a bit out of my league.

I've attached a workspace where I at least help you with the formatting and extracting of the Object nodes (where the attributes you want reside).

 

I think you need an XQuery to extract the properties into attributes, but that is something I have no idea how to do.

 

https://docs.safe.com/fme/html/FME-Form-Documentation/FME-Transformers/Transformers/xmlxqueryextractor.htm


This issue is more complex than I was expecting and it's a bit out of my league.

I've attached a workspace where I at least help you with the formatting and extracting of the Object nodes (where the attributes you want reside).

 

I think you need an XQuery to extract the properties into attributes, but that is something I have no idea how to do.

 

https://docs.safe.com/fme/html/FME-Form-Documentation/FME-Transformers/Transformers/xmlxqueryextractor.htm

Many thanks @oscard​ , I will keep looking around.

 

With regards,

 

Keller.


I can parse this, but not in an elegant way. What I did:

  • Read it as text.
  • Replaced &lt; and &gt; with < and > using the TextDecoder set to HTML.
  • Fragmented and flattened on Envelope/Body/ExportDataResponse/ExportDataResult/Data/Object
  • Exploded the list with properties to features.
  • Created attributes from Name and Value.
  • Merged to original object.

I can parse this, but not in an elegant way. What I did:

  • Read it as text.
  • Replaced &lt; and &gt; with < and > using the TextDecoder set to HTML.
  • Fragmented and flattened on Envelope/Body/ExportDataResponse/ExportDataResult/Data/Object
  • Exploded the list with properties to features.
  • Created attributes from Name and Value.
  • Merged to original object.

Thanks @nielsgerrits​ going to try it right away.


 

Hi @jdh​ ,@Takashi Iijima​ , in another question i saw you guys helped out with the same problem(https://community.safe.com/s/question/0D54Q000080hfJ2SAl/extract-attributes-from-xml-attribute), i have tried following the answers but i seem not to get the same result. any idea of how i can extract the Property Names and Values only(in bold)? (It was a SOAP XML then fragmented and formarted it.Here is the XML.

 

Regards,

Keller.

<?xml version="1.0" encoding="UTF-8"?>

<Data>

   <Object Type="ProcessFunctionMeasurementPointValue" Action="InsertOrUpdate">

      <Property Name="Equipment-ID" Value="B0000481"></Property>

      <Property Name="Client-ID" Value="029772"></Property>

      <Property Name="Height" Value="16.04"></Property>

      <Property Name="Date" Value="2023-03-27T15:17:00+02:00"></Property>

   </Object>

   <Object Type="ProcessFunctionMeasurementPointValue" Action="InsertOrUpdate">

      <Property Name="Equipment-ID" Value="B0000481"></Property>

      <Property Name="Client-ID" Value="029772"></Property>

      <Property Name="Height" Value="1604.00"></Property>

      <Property Name="Date" Value="2023-03-14T16:58:00+01:00"></Property>

   </Object>

</Data>


Using the xml that @oscard​  has posted

XMLFragmenter to  with Elements to Match set to Object to get a feature per object

XMLXQueryExtractor with the following Xquery

declare namespace x='http://tempuri.org/';
let $p := //x:Property
for $i in $p
return (
fme:set-attribute($i/@Name/string(),$i/@Value/string())
)

Then expose the relevant attributes

image


 

Hi @jdh​ ,@Takashi Iijima​ , in another question i saw you guys helped out with the same problem(https://community.safe.com/s/question/0D54Q000080hfJ2SAl/extract-attributes-from-xml-attribute), i have tried following the answers but i seem not to get the same result. any idea of how i can extract the Property Names and Values only(in bold)? (It was a SOAP XML then fragmented and formarted it.Here is the XML.

 

Regards,

Keller.

<?xml version="1.0" encoding="UTF-8"?>

<Data>

   <Object Type="ProcessFunctionMeasurementPointValue" Action="InsertOrUpdate">

      <Property Name="Equipment-ID" Value="B0000481"></Property>

      <Property Name="Client-ID" Value="029772"></Property>

      <Property Name="Height" Value="16.04"></Property>

      <Property Name="Date" Value="2023-03-27T15:17:00+02:00"></Property>

   </Object>

   <Object Type="ProcessFunctionMeasurementPointValue" Action="InsertOrUpdate">

      <Property Name="Equipment-ID" Value="B0000481"></Property>

      <Property Name="Client-ID" Value="029772"></Property>

      <Property Name="Height" Value="1604.00"></Property>

      <Property Name="Date" Value="2023-03-14T16:58:00+01:00"></Property>

   </Object>

</Data>

Hi @keller​ ,

Here is another solution.

You can convert the source XML you posted at first to a JSON document with XMLXQueryExtractor, and then extract required attributes with JSONFragmenter.

See the attached workspace example to learn more.

 

parse_xml_as_json XQuery Expression

declare namespace temp="http://tempuri.org/";
t
    for $x in parse-xml(//temp:ExportDataResult/text())//Object
    return
    {|
        {
            "Type" : data($x/@Type),
            "Action" : data($x/@Action)
        },
        for $p in $x/Property
        return { data($p/@Name) : data($p/@Value) }
    |}
]

Resulting JSON Document

b
   {
      "Type" : "ProcessFunctionMeasurementPointValue",
      "Action" : "InsertOrUpdate",
      "Equipment-ID" : "ST0000481",
      "Client-ID" : "029772",
      "Height" : "16.04",
      "Date" : "2023-03-27T15:17:00+02:00"
   },
   {
      "Type" : "ProcessFunctionMeasurementPointValue",
      "Action" : "InsertOrUpdate",
      "Equipment-ID" : "ST0000481",
      "Client-ID" : "029772",
      "Height" : "1604.00",
      "Date" : "2023-03-14T16:58:00+01:00"
   }
]

 


Reply