Solved

multi-level XMLTemplater


Badge +11

Hello colleagues @Takashi Iijima​ . For the third day I have been trying to figure out how to configure Xmltemplate, but my programming skills are not enough((. Help to configure the Xml template to create a working xml file.

Here is a sample of the result, all the pictures are arranged in their own groups

<?xml version="1.0" encoding="utf-8"?>
<BlocksExchange version="3.2">
<Block>
<Name>Block_223-32</Name>
<Photogroups>
<Photogroup>
<Name>Photogroup 100_NS</Name>
<ImageDimensions>
<Width>31580</Width>
<Height>13904</Height>
</ImageDimensions>
<CameraModelType>Perspective</CameraModelType>
<CameraModelBand>Visible</CameraModelBand>
<FocalLength>149.842</FocalLength>
<SensorSize>118.741</SensorSize>
<CameraOrientation>XRightYDown</CameraOrientation>
<Photo>
<Id>682</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/NS/2801_3416_100_NS.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
<LensModel>-- mm f/--</LensModel>
</ExifData>
</Photo>
<Photo>
<Id>683</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/NS/2801_3417_100_NS.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
<LensModel>-- mm f/--</LensModel>
</ExifData>
</Photo>
</Photogroup>
<Photogroup>
<Name>Photogroup 163_OB</Name>
<ImageDimensions>
<Width>11664</Width>
<Height>8750</Height>
</ImageDimensions>
<CameraModelType>Perspective</CameraModelType>
<CameraModelBand>Visible</CameraModelBand>
<FocalLength>145.929</FocalLength>
<SensorSize>43.7814</SensorSize>
<CameraOrientation>XRightYDown</CameraOrientation>
<Photo>
<Id>3783</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OB/2851_1518_163_OB.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
</ExifData>
</Photo>
<Photo>
<Id>3784</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OB/2851_1519_163_OB.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
</ExifData>
</Photo>
</Photogroup>
<Photogroup>
<Name>Photogroup 161_OF</Name>
<ImageDimensions>
<Width>11664</Width>
<Height>8750</Height>
</ImageDimensions>
<CameraModelType>Perspective</CameraModelType>
<CameraModelBand>Visible</CameraModelBand>
<FocalLength>145.619</FocalLength>
<SensorSize>43.7814</SensorSize>
<CameraOrientation>XRightYDown</CameraOrientation>
<Photo>
<Id>3832</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OF/2601_1214_161_OF.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
<LensModel>-- mm f/--</LensModel>
</ExifData>
</Photo>
<Photo>
<Id>3833</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OF/2601_1215_161_OF.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
<LensModel>-- mm f/--</LensModel>
</ExifData>
</Photo>
</Photogroup>
<Photogroup>
<Name>Photogroup 162_OL</Name>
<ImageDimensions>
<Width>8750</Width>
<Height>11664</Height>
</ImageDimensions>
<CameraModelType>Perspective</CameraModelType>
<CameraModelBand>Visible</CameraModelBand>
<FocalLength>145.921</FocalLength>
<SensorSize>43.7814</SensorSize>
<CameraOrientation>XRightYDown</CameraOrientation>
<Photo>
<Id>7486</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OL/2851_2012_162_OL.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
</ExifData>
</Photo>
<Photo>
<Id>7487</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OL/2851_2013_162_OL.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
</ExifData>
</Photo>
</Photogroup>
<Photogroup>
<Name>Photogroup 160_OR</Name>
<ImageDimensions>
<Width>8750</Width>
<Height>11664</Height>
</ImageDimensions>
<CameraModelType>Perspective</CameraModelType>
<CameraModelBand>Visible</CameraModelBand>
<FocalLength>145.904</FocalLength>
<SensorSize>43.7814</SensorSize>
<CameraOrientation>XRightYDown</CameraOrientation>
<Photo>
<Id>9306</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OR/2851_2125_160_OR.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
</ExifData>
</Photo>
<Photo>
<Id>9307</Id>
<ImagePath>X:/Common/PGMtry2/Ishodnye_photo/Sigma_2020/Images/OR/2851_2126_160_OR.jpg</ImagePath>
<Component>0</Component>
<ExifData>
<Make>Adobe Systems Inc.</Make>
<Model>Tiff File</Model>
</ExifData>
</Photo>
</Photogroup>
</Photogroups>
<ControlPoints/>
<PositioningConstraints/>
</Block>
</BlocksExchange>

i also attached a sample of the original data.

A giant thank you!

PS i am use FME vers 2021.0.3.0

icon

Best answer by debbiatsafe 10 September 2021, 01:32

View original

8 replies

Userlevel 3
Badge +17

Hi @muzhnasto​ 

Instead of feeding all features to each sub-template in the XMLTemplater, I would suggest aggregating the features based on the appropriate attribute for the sub-template. Then to maintain the hierarchal structure, use the syntax detailed here in the documentation under Selecting the Sub-Feature to Process heading. 

Note: you will have to add commas between unrelated XML fragments. For example, in the snippet below after /Name, /Photogroups, and ControlPoints/.

<Name>Block_{fme:get-attribute("NAME")}</Name>,
<Photogroups>{fme:process-features("SUB_GROUP","NAME", fme:get-attribute("NAME"))}</Photogroups>,
<ControlPoints/>

Since you did not share the data, I attempted to recreate some data using the XML output you have shared. I have attached a workspace that should create something close to your desired output. I hope it helps!

Badge +11

Hi @muzhnasto​ 

Instead of feeding all features to each sub-template in the XMLTemplater, I would suggest aggregating the features based on the appropriate attribute for the sub-template. Then to maintain the hierarchal structure, use the syntax detailed here in the documentation under Selecting the Sub-Feature to Process heading. 

Note: you will have to add commas between unrelated XML fragments. For example, in the snippet below after /Name, /Photogroups, and ControlPoints/.

<Name>Block_{fme:get-attribute("NAME")}</Name>,
<Photogroups>{fme:process-features("SUB_GROUP","NAME", fme:get-attribute("NAME"))}</Photogroups>,
<ControlPoints/>

Since you did not share the data, I attempted to recreate some data using the XML output you have shared. I have attached a workspace that should create something close to your desired output. I hope it helps!

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

Badge +6

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

Hi @muzhnasto​, These articles will help you get started.

https://community.safe.com/s/article/xml-reader-configuration

https://community.safe.com/s/article/reading-xml-simple-approach-using-feature-paths

If you could share your .xml as a new thread, it should grab the attention of the greater community. Hope this helps!

Badge +11

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

Hi @jennaatsafe​ 

I don't need to read it, I need to create separate xml based on existing data ;)

Badge +6

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

In that case, could you share your existing data with us? Hopefully I can mock up a workspace that does the trick :)

Badge +11

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

@jennaatsafe​  the workspace from @debbiatsafe​  has already solved most of the problem, and an example of the data from which it is necessary to form xml in the archive ask_xml.zip (ffs format)

P S archive for 4 messages above :)

Userlevel 3
Badge +17

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

Hi @muzhnasto​ 

You should be able to create separate XML output based on the NAME attribute by enabling Group By Processing on NAME in the XMLTemplater and sending one feature per unique NAME value to Root template.

In addition, you would want to adjust the Aggregator that is connected to the SUB_GROUP port to aggregate based on ImageCameraName and NAME. This allows the correct hierarchy to be maintained.

As a general note, there are some binary floating point rounding issues for the attributes FocalLength(mm) and SensorSize. You can work around this by using the XQuery round function (fn:round), as shown in the SUB_GROUP sub template. Hope this helps.

Badge +11

Hi @debbiatsafe​ 

Thank you so much for your answer. Sorry for the impudence, but I ask you to show how to create separate xml for each block based on the value 'NAME'

Hi @debbiatsafe​  this is incredible, thank you very much 👍 🍻

Reply