helpen xml - De Unix-en Linux Forum
The UNIX and Linux Forums  


Go Back   De Unix-en Linux Forum > Top Forums > Programmeren en Shell Scripting
.
google unix.com



Programmeren en Shell Scripting Post vragen over KSH, CSH, SH, Bash, Perl, PHP, sed, awk en andere shell scripts en shell scripting talen hier.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Zoeken in deze Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-07-2008
uwork72 uwork72 is offline
Geregistreerde gebruiker
  
 

Join Date: Aug 2008
Posts: 32
helpen xml

Fractie,


Code:
$ cat 2233
12236 ID2
12239 ID3

Please guide me to construct the following XML from the above input.


<Comp>
        <main>
                <hlp fS="12236" eS="12237">
                        <std no="2233" />
                        <id="ID2"/>
                </hlp>
                <hlp fS="12239" eS="12240">
                        <std no="2233" />
                        <id="ID3"/>
                </hlp>
        </main>
</Comp>

** eS is +1 of fS value
** std no is the file name

  #2 (permalink)  
Old 10-07-2008
tijdperk era is offline Forum Advisor  
Herder van Nutteloze Cats (On Sabbatical)
  
 

Join Datum: maart 2008
Locatie: / er / is / alleen / bin / sh
Berichten: 3652
Wat heb je geprobeerd, welke delen hebt u problemen met? Heeft u een voorkeur voor een bepaalde uitvoering taal?

(Is het niet een tikkeltje moronic om een veldwaarde die altijd een ander veld waarde plus een?)
  #3 (permalink)  
Old 10-07-2008
summer_cherry summer_cherry is offline Forum Advisor  
Geregistreerde gebruiker
  
 

Join Date: Jun 2007
Locatie: Beijing China
Berichten: 1.089
perl

hi proberen hieronder perl script
zeggen dat het script naam is a.pl, onder commando kan het adres van uw probleem.

Citaat:
perl a.pl 2233


Code:
format STDOUT_TOP =
<Comp>
        <main>
.
format STDOUT =
		<hlp fs="@<<<<" es="@<<<<">
		$text1     $text2  
			<std no="@<<<"/>
			$text3
			<id="@<<"/>
			$text4
		</hlp>
.
$file=shift;
open(FH,"<$file") or die "Can not open file";
while(<FH>){
	@arr=split(" ",$_);
	$text1=$arr[0];
	$text2=$arr[0]+1;
	$text3=$file;
	$text4=$arr[1];
	write;
}
print "        </main>\n";
print "</Comp>\n";
close(FH);

  #4 (permalink)  
Old 10-07-2008
uwork72 uwork72 is offline
Geregistreerde gebruiker
  
 

Join Date: Aug 2008
Posts: 32
Era, bedankt voor het beantwoorden. Ik probeerde slechts een vermelding in de input file; zoiets


Code:
....
FILE=$1
fS=$(awk '{print $1}' $FILE)
((eS=fS+1))

echo "<Comp>" >> myxml
...
...

Maar ik ben niet in staat om hetzelfde te doen als num-items in de input-bestand in meer dan 1. Please help.
  #5 (permalink)  
Old 10-09-2008
uwork72 uwork72 is offline
Geregistreerde gebruiker
  
 

Join Date: Aug 2008
Posts: 32
cfajohnson, dat werkte heel goed voor me. Bedankt.
  #6 (permalink)  
Old 10-07-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmeur, auteur
  
 

Join Datum: maart 2007
Plaats: Toronto, Canada
Berichten: 2.362
Citaat:
Oorspronkelijk geplaatst door uwork72 View Post
Fractie,


Code:
$ cat 2233
12236 ID2
12239 ID3

Please guide me to construct the following XML from the above input.


<Comp>
        <main>
                <hlp fS="12236" eS="12237">
                        <std no="2233" />
                        <id="ID2"/>
                </hlp>
                <hlp fS="12239" eS="12240">
                        <std no="2233" />
                        <id="ID3"/>
                </hlp>
        </main>
</Comp>

** eS is +1 of fS value
** std no is the file name

Dit doet wat je gevraagd voor:

Code:
file=2233
{
 read num1 id1
 read num2 id2
} < "$file"
fmt='<Comp>
        <main>
                <hlp fS="%d" eS="%d">
                        <std no="%d" />
                        <id="%s"/>
                </hlp>
                <hlp fS="%d" eS="%d">
                        <std no="%d" />
                        <id="%s"/>
                </hlp>
        </main>
</Comp>'

printf "%fmt\n" "$num1" "$(( $num1 + 1 ))" "$file" "$id1" \
                "$num2" "$(( $num3 + 1 ))" "$file" "$id2"

Meer waarschijnlijk, wat je wil, is:


Code:
file=2233
head='<Comp>
        <main>'
fmt='                <hlp fS="%d" eS="%d">
                        <std no="%d" />
                        <id="%s"/>
                </hlp>
'

tail='        </main>
</Comp>'

{
 printf "%s\n" "$head"
 while read nnum id
 do
   printf "$fmt" "$num" "$(( $num + 1 ))" "$file" "$id"
 done < "$file"
 printf "%s\n" "$tail"
} > NEWFILE


## (untested)

Closed Thread

Bladwijzers

Labels
perl, perl verschuiving, verschuiven, verschuiving perl

Thread Tools Zoeken in deze Thread
Zoeken in deze Thread:

Uitgebreid zoeken
Display Modes Beoordeel deze draad
Beoordeel deze draad:

Posting Regels
Jij mag niet Post Nieuwe threads
Jij mag niet na antwoorden
Jij mag niet post attachments
Jij mag niet bewerk uw berichten

BB code is Aan
Smilies zijn Aan
[IMG] code Aan
HTML-code is Uit
Trackbacks zijn Aan
Pingbacks zijn Aan
Refbacks zijn Aan




Alle tijden zijn GMT -4. Het is nu 06:07.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Vertalingen Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
De Unix-en Linux Forums Copyright © 1993-2009. Alle rechten Reserved.Ad Beheer door RedTyger

Content Relevante URL's door vBSEO 3.2.0