ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
RE: XML Twig - perl
by Mark - BLS CTR Thomas other posts by this author
Sep 29 2004 7:41AM messages near this date
view in the new Beta List Site
Perl OO | XML Twig - perl
Bhuvana,

XML questions are best asked on the perl-XML list. Many Twig users frequent
that list (even the author chimes in from time to time).

I'm not all that familiar with Twig, so what I can do is give you working
XML::LibXML code:

my $doc = XML::LibXML-> new->parse_file($ARGV[0]);
my @dl_nodes = $doc-> findnodes('//dl');
foreach my $dl (@dl_nodes) {

	#create replacement dl element
	my $new_dl = XML::LibXML::Element-> new('dl');
	$new_dl-> appendText("\n");

	#process the old dl element
	my $text = $dl-> textContent;
	foreach $line (split /\s*\n\s*/, $text) {
		my ($first, $second) = split /\s+/, $line, 2;
		next unless $second; #skip incomplete lines
		$new_dl-> appendTextChild('first',$first);
		$new_dl-> appendTextChild('second',$second);
		$new_dl-> appendText("\n");
	}

	#now perform replacement
	$dl-> replaceNode($new_dl);
}
print $doc-> toString;




-- 
Mark Thomas                    Thomas.Mark@[...].gov 
Internet Systems Architect     DigitalNet, Inc. 


>  -----Original Message-----
>  
>  Hello,
>  
>  Using xml twig, I am trying to supply two elements in a line 
>  with the separator tab.
>  
>  Ex:
>  <c>
>  <dl>
>  ABC    CDE
>  add    eerwe
>  sdfsdfs    erewrwe
>  </dl>
>  </c>
>  
>  Expected Result:
>  <c>
>  <dl>
>  <first>ABC</first><second>CDE</second>
>  <first>add</first><second>eerwe</second>
>  <first>sdfsdfs</first><second>erewrwe</second>
>  </dl>
>  </c>

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved