Suppose there is an XML content as follows:-<address>
<city>bbsr</city>
<country>india</city>
<city>ctc</city>
<country>pakistan</city>
</address>
We want to get data within the attribute <city> i.e “bbsr” and “ctc” separated by carraige return.
So , here is a custom function for it.
XMLParse(xml;textWithBrace;count1)
xml = “<address>
<city>bbsr</city>
<country>india</city>
<city>ctc</city>
<country>pakistan</city>
</address>”
textWithBrace = “<city>”
count1 = 1 (always)
——————————————————————————–
Let (
[ patterns = PatternCount ( xml ; textWithBrace);
posn = Position ( xml ; textWithBrace ; 1;count1 );
posnRight = PositionNextRightBrace ( xml ; posn ; 1 );
posnLeft = PositionNextLeftBrace ( xml ; posnRight ; 1 );
count1 = count1 + 1
patterns <1 ; “No matching attributes”;
count1 > patterns ; Middle ( xml ; posnRight ; posnLeft – posnRight -1) ;
Middle ( xml ; posnRight ; posnLeft – posnRight – 1 ) & “¶” & XMLParse(xml;textWithBrace;count1)
)
)
——————————————————————————–
Supporting custom functions:-
1.PositionNextRightBrace(text ; posLeftBrace ; count1)
——————————————————————————–
Let (
[text = xml;
data =Middle ( text ; count1 + posLeftBrace ; 1 )
];
If ( data = “>” ; posLeftBrace + count1+1 ; PositionNextRightBrace(text ; posLeftBrace ; count1+1))
)
——————————————————————————–
2.PositionNextLeftBrace(text ; posRightBrace ; count1)
——————————————————————————–
Let (
[text = xml;
data =Middle ( text ; count1 + posRightBrace ; 1 )
];
If ( data = “<” ; posRightBrace + count1+1 ; PositionNextLeftBrace(text ; posRightBrace ; count1+1))
)
——————————————————————————–
Thanks
Happy FileMaking
