Book a Demo

Author Topic: Parse XML into template fragment  (Read 2882 times)

royvanmarrewijk

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Parse XML into template fragment
« on: February 08, 2022, 06:32:08 pm »
Hi,

I would like to parse the data from an external XML file into a document using the EA document generator and a template fragment. I tried to follow this tutorial:
https://sparxsystems.com/enterprise_architect_user_guide/15.2/model_publishing/custom_xml_fragment.html but it didn't work for me. I tested the link I put in and it works within my browser so I think that isn't the problem. Does anyone of you have a code example for how to import a XML into a document using a script or the custom script in the template fragment?

Roy

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Parse XML into template fragment
« Reply #1 on: February 08, 2022, 06:55:00 pm »
Roy,

What didn't work?
An XML fragment requires an xml file in the precise format specified in the manual.
You can't simply provide any xml file and expect EA to make something out of it.

If you have data in an xml file that you want to include in your document, you are probably better of creating a script fragment that parses the xml file and returns the xml format expected by EA.

Geert

royvanmarrewijk

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Re: Parse XML into template fragment
« Reply #2 on: February 08, 2022, 07:22:15 pm »
Hi Geert,

Thanks for the quick reaction! The XML contains the data from the example:

Code: [Select]
<EADATA>
         <Dataset_0>
             <Data>
                 <Row Name="NameValue" Second="Value2"></Row>
                 <Row Name="NameValue2"></Row>
             </Data>
         </Dataset_0>
     </EADATA>

The custom script in the template fragment contains the following code:
Code: [Select]
Filename = \\Serverpath\test.xml
The template fragment only catches the name field using the 'Insert custom field' function
Code: [Select]
custom>
{Name}
<custom

This is what I think the tutorial is says I should do but the result is null.

Roy

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Parse XML into template fragment
« Reply #3 on: February 08, 2022, 07:46:54 pm »
Yeah, that pretty much looks like it should work.

Have you tried with a local xml file (instead of a server file)?

There is also an XPATH expression in the manual, but it isn't mentioned further on. Maybe it needs that xpath expression anyway?

I remember there being detailed step by step instructions and examples to create template fragments.
Unfortunately I can't remember where exactly I found those, but if you can find them, they might give you some more insight.
Often a working example helps a lot more than pages of instructions.

(I haven't used the xml fragment myself, so I can't share a working example)


Geert