/
position.m
39 lines (33 loc) · 1.12 KB
/
position.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function [string,p_st,p_ed]=position(str_long,str_ID)
% Retrieve the value of an attribute (`str_ID`) in the line (`str_long`) of the
% XML file and identify the starting and ending indices of the value in the
% attribute line of the XML file.
%
% USAGE:
%
% [string, p_st, p_ed] = position(str_long, str_ID)
%
% INPUTS:
% str_long: A string of the line of the XML file
% str_ID: The name of the attribute
%
% OUTPUTS:
% string: The value of the attribute
% p_st: The starting index of the value
% p_ed: The ending index of the value
%
% .. Author: - Longfei Mao Oct/2014
ind_pos=strfind(str_long,str_ID); % name='metaid';
l=length(str_ID)+2;
p_st=ind_pos{1}+l
% end_rem=strfind(str_long{1}(ind_pos{1}:end),'"');
end_rem=strfind(str_long{1}(p_st:end),'"');
% disp(str_long{1}(ind_pos{1}:end));
disp(str_long{1}(p_st:end));
% if size(end_rem)
% end_rem{1}=[];
% end
p_ed=end_rem(1)+p_st-2;
disp(p_ed);
string=str_long{1}(p_st:p_ed);
end