can I read an XML file (UTF8) and parse out the contents of one element. I only need the text in between <text> and </text>. And this element only comes up once in the xml file.
You have to somehow get the text mass in to a field (import maybe), to parse your part out.
I frequently use a general text parsing custom function that I created many years ago to do such things.
Syntax: ~ParseText ( Text ; Start ; End ; Number )
Count = PatternCount ( Text ; Start )
XNumber = Case( GetAsNumber( Number ) ≤ 1 ; 1 ; Floor( GetAsNumber( Number ) ) )
SLength = Length ( Start )
SPos = Case( IsEmpty( Start ) ; 1 ; Position ( Text ; Start ; 0 ; XNumber ) + SLength )
EPos = Case( IsEmpty( End) ; Length ( Text ) + 1 ; Position ( Text ; End ; SPos ; 1 ) )
TLength = EPos - Spos
Result = Middle ( Text ; SPos ; TLength )
Error = GetAsBoolean( ( ( ( GetAsNumber( XNumber ) > GetAsNumber( Count ) ) or ( GetAsNumber( Count ) < 1 ) ) and ( not IsEmpty( Start ) ) ) or IsEmpty( Text ) )
Case( not Error ; Result )
The syntax in your case would be something like:
~ParseText ( YourTable::YourField ; "<text>" ; "</text>" ; 1 )
With best regards Magnus Fransson.
There are several custom functions (require FMPAdvanced to edit/add) that "parse XML". Here is one that would work for you question:
ExtractData ( XML ; Attribute ; Instance )
There are other custom functions. If you do not have FMPAdvanced, I have been able to use the same logic in a CF to script (looping if necessary).
If you need more complex, there are also several plug-ins to "parse XML"
If you wish to import a lot of XML, XSLT can also be used to transform different schema/formats to the FMPXMLRESULT grammar required for import to FMP.
Can you show us the xml and give us the field you want to import?
Thanks for the answers so far.
This would be the xml.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="C:\Program Files\Oxygen XML Editor 17\frameworks\tei\xml\tei\css\tei_oxygen_ERC.css"?>
<!DOCTYPE TEI SYSTEM "http://www.tei-c.org/Vault/P5/2.2.0/xml/tei/custom/schema/dtd/tei_all.dtd">
<TEI xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<div type="translation" xml:lang="en">
ok, your original post asked for between <text> & </text>
you are going to have several things "to get". Likely, these two would be different values:
"ab", where the XPath => text/body/div[@type='edition']/ab
"ab", where the XPath => text/body/div[@type='translation']/ab
what do you really want and where do you want it?
EDITED as text was munched in reply-by-email
Thanks, I am totally fine with getting all that is within the text element. So the first answer will probably do the trick.
Sorry, one more question. I noticed, that I do need FM Advanced, right?! We got Server and several FM Pros. If I then write the Function in Advanced, will our team members be able to use it in their FM Pro Version?
if you "install" the Custom Function into your file(s) with FMPA, then any FMPro can use the function. You only need the Advanced to edit/create custom functions.
Retrieving data ...