Sorry about that. If you would have given us a sample input file and the output that should be produced from that input, I would have caught that early lines in input files were being dropped. There is nothing in my code that would remove <carriage-return> characters from existing lines in the file, but it didn't put <carriage-return>s in the lines it adds (and if you wanted DOS format text files, that is something we would have expected you to explicitly state in your requirements). Does the following replacement come closer to meeting your requirements?
Changes from the previous version are shown in red.
This User Gave Thanks to Don Cragun For This Post:
Hello,
I'm new in Shell scripting but i should write a script, which inserts the license header out of a txt-File into the files in our Projekt. For the Java classes it runs without Problems but for XML files not. At xml-files i have to put the license Header after the xml-Header (?xml... (1 Reply)
Greetings all,
I am trying to match a string, and after that insert a few lines above that match.
The string is "Version 1.0.0". I need to insert a few lines ONLY above the first match (there are many Version numbers in the file). The rest of the matches must be ignored. The lines I need to... (2 Replies)
Hello,
I have the following variables set in my env
echo $MY_XSD_FILE
/home/jak/sample.xsd
echo $MY_INTERVAL_VALUE
4
I want to insert them between the xml tags in my xml file
cat sample.xml
:::::::::::::::
:::::::::::::::
<property name="FILE"></property>
:::::::::::::::::::::::... (2 Replies)
Hi,
i have an xml file and i want to edit a new sub node in a file
like
val="<activity android:label="@string/app_name" android_name=".MainActivity1" android:launchMode="singleTask" android:screenOrientation="portrait"
... (1 Reply)
Hi!
Considering below text, how would I use sed to insert text right below the v0005-line, using the SEPARATOR-line as a pattern to search for, so two lines above the separator? I can do it right above the separator, but not 2 lines...
# v0004 - Some text
# v0005 - More text
#... (5 Replies)
The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Have a file which has the create statement like below
create table emp
( empno integer,
empname char(50))
primary index(empno);
i need to find a string starting with create and ends with semi-colon ;. if so insert the below statement before create statement
rename table emp to emp_rename;... (2 Replies)
i'm using the following code to add the entire content of a file (/tmp/resources.txt) to the line directly below the line containing a pattern (wonderful) in the file mainfile.txt:
sed '/^wonderful/ r /tmp/resources.txt' mainfile.txt
the problem is, it adds the entire content of... (1 Reply)
Hello Team,
I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file.
Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
file1.txt
abc12345
def12345
ghi54321
...
file2.txt
abc1,text1,texta
abc,text2,textb
def123,text3,textc
gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
LEARN ABOUT DEBIAN
xml::smart::tutorial
XML::Smart::Tutorial(3pm) User Contributed Perl Documentation XML::Smart::Tutorial(3pm)NAME
XML::Smart::Tutorial - Tutorial and examples for XML::Smart.
SYNOPSIS
This document is a tutorial for XML::Smart and shows some examples of usual things.
Working with contents:
In XML::Smart the key CONTENT is reserved and shouldn't be used directly, since XML::Smart will deal with the convertion of arguments to
node contents, including multiple node contents autimatically.
What happens when you set a value:
$xml->{root}{foo} = 'simple value' ;
Here foo will be a normal argument/attribute value, and will generate this XML data:
<root foo="simple value"/>
But if you insert some tag or lines in the values by default XML::Smart will convert it to a node content:
$xml->{root}{foo} = "line0
lien1
line2
" ;
And will generate that XML data:
<root>
<foo>line0
lien1
line2
</foo>
</root>
But what you can do if you want to force some type, let's say, have a node content with a simple value:
$xml->{root}{foo} = 'simple value' ;
$xml->{root}{foo}->set_node(1) ;
And will generate that XML data:
<root>
<foo>simple value</foo>
</root>
Multiple contents:
When you have interpolated content/data you need to work in a different. Let's say that you load this XML data:
<root>
content0
<tag1 arg="1"/>
content1
</root>
If you access directly the root key as string you will get all the content parts grouped. So, this code:
my $xml = new XML::Smart(q`
<root>
content0
<tag1 arg="1"/>
content1
</root>
`,'smart') ;
print "#$xml->{root}#" ;
Will print that:
#
content0
content1
#
To access each part of the content independently you should use an array that receive the method content():
my @content = $xml->{root}->content ;
print "#$content[0]#
" ;
And this will print that:
#
content0
#
Now to set the multiple content values you should use the method content() with 2 arguments:
$xml->{root}->content(0,'new content') ;
And now the XML data produced will be:
<root>new content<tag1 arg="1"/>
content1
</root>
If you use the method content() with only one argument it will remove all the multiple contents and will set the new value in the place of
the 1st content.
Setting the XML Parser.
By defaul XML::Smart will use XML::Parser or XML::Smart::Parser (in this order of preference) to load a XML data.
To force or define by your self the parser you can use the 2nd argument option when creating a XML::Smart object:
my $xml = new XML::Smart( 'some.xml' , 'XML::Parser' ) ;
## and
my $xml = new XML::Smart( 'some.xml' , 'XML::Smart::Parser' ) ;
XML::Smart also has an extra parser, XML::Smart::HTMLParser, that can be used to load HTML as XML, or to load wild XML data:
my $xml = new XML::Smart( 'some.xml' , 'XML::Smart::HTMLParser' ) ;
Aliases for the parser options:
SMART|REGEXP => XML::Smart::Parser
HTML => XML::Smart::HTMLParser
So, you can use as:
my $xml = new XML::Smart( 'some.xml' , 'smart' ) ;
my $xml = new XML::Smart( 'some.xml' , 'html' ) ;
Customizing the Parser.
You can customize the way that the parser will treat the XML data:
Forcing nodes/tags and arguments/attributes to lowercase or upercase:
## For lower case:
my $xml = new XML::Smart( 'some.xml' ,
lowtag => 1 ,
lowarg => 1 ,
) ;
## For uper case:
my $xml = new XML::Smart( 'some.xml' ,
upertag => 1 ,
uperarg => 1 ,
) ;
Loading arguments without values (flags) as a TRUE boolean:
** Note, this option will work only when the XML is parsed by XML::Smart::HTMLParser, since only it accept arguments without values!
my $xml = new XML::Smart(
'<root><foo arg1="" flag></root>' ,
'XML::Smart::HTMLParser' ,
arg_single => 1 ,
) ;
Here's the tree of the example above:
'root' => {
'foo' => {
'flag' => 1,
'arg1' => ''
},
},
Customizing the parse events:
XML::Smart can redirect the parsing process to personalized functions:
my $xml = XML::Smart->new( 'some.xml' ,
on_start => &on_start ,
on_char => &on_char ,
on_end => &on_end ,
) ;
sub on_start {
my ( $tag , $pointer , $pointer_back ) = @_ ;
$pointer->{$tag}{type_user} = 1 if $tag =~ /(?:name|age)/ ;
}
sub on_char {
my ( $tag , $pointer , $pointer_back , $content) = @_ ;
$$content =~ s/s+/ /gs ;
}
sub on_end {
my ( $tag , $pointer , $pointer_back ) = @_ ;
$pointer->{$tag}{type_extra} = 1 if $tag =~ /(?:more|tel|address)/ ;
}
AUTHOR
Graciliano M. P. <gm@virtuasites.com.br>
I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P
Enjoy and thanks for who are enjoying this tool and have sent e-mails! ;-P
ePod
This document was written in ePod (easy-POD), than converted to POD, and from here you know the way.
perl v5.10.1 2004-12-08 XML::Smart::Tutorial(3pm)