Solved

Remove Attributes from a XML node string

Posted on 2006-07-04
2
370 Views
Last Modified: 2013-11-19
hey,
if I have a string like so:

<record  spacing="1" padding="1"><trec><thread case="new">Date</thread></trec></record>

its just some xml structure made into a string...
I need a string function that will remove all the attributes from certain nodes:

function StripAttribs(Astring, ATag: string):string;
result string would =

<record><trec><thread case="new">Date</thread></trec></record>

if ATag = 'record' that is
I have made 2 functions myself but I think they are clunky, Im hoping someone might already have something better
0
Comment
Question by:LMuadDIb
2 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 300 total points
ID: 17040529
this would be a pretty good solution as it is speed and memory optimized (one pass only). Small speed optimizations are still possible.

function StripAttribs(s, t: string):string;
var i:integer; tag:string;
  function getnexttag:boolean;
  begin
    while (i<=length(s)) and (s[i]<>'<') do
      inc(i);
    if s[i]='<' then
    begin
      inc(i);
      tag:='';
      while (i<=length(s)) and (not (s[i] in [' ','>'])) do
      begin
        tag:=tag+s[i];
        inc(i);
      end;
      result:=tag<>'';
    end         else
      result:=false;
  end;
begin
  i:=1;
  t:=lowercase(t);
  while getnexttag do
  begin
    if lowercase(tag)=t then
      while s[i]<>'>' do
        delete(s,i,1);
  end;
  result:=s;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  showmessage(StripAttribs('<record  spacing="1" padding="1"><trec><thread case="new">Date</thread></trec></record>','record'));
end;
0
 
LVL 4

Author Comment

by:LMuadDIb
ID: 17044464
thanks ciuly,
works nice :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now