deadpickle has asked for the wisdom of the Perl Monks concerning the following question:
So now what? How do I fix this XML file so that it will validate ok?Received message: n="1.0" encoding="UTF-8"?> <Capabilities xsi:schemaLocation="http://Capabilities.CUIntegration.co +m capabili ties.xsd" xmlns="http://Capabilities.CUIntegration.com" xmlns:xsi="htt +p://www.w3 .org/2001/XMLSchema-instance"> <VehicleID>String</VehicleID> <System> <ID>Servo</ID> <AcceptedCommands>Loiter</AcceptedCommands> <AvailableStreams>Telemetry</AvailableStreams> </System> </Capabilities> :1: parser error : Start tag expected, '<' not found n="1.0" encoding="UTF-8"?> ^ The document has no document element.
Here are the codes:
Server
Client#!/usr/bin/perl -w use strict; use IO::Socket; use XML::LibXML; my $MySocket=new IO::Socket::INET->new(LocalPort=>1234,Proto=>'udp'); my $parser = XML::LibXML->new; $parser->recover(1); my $xml1 = ""; my $schema = XML::LibXML::Schema->new(location => 'C:\Users\deadpickle +\Desktop\UAS\GRRUVI_1.50\panel\capabilities.xsd' ); while(1) { if ($MySocket) { $MySocket->recv($xml1,2669); print "\nReceived message: ", $xml1,"\n"; my $doc = $parser->parse_string($xml1); #$parser->validation(1); eval { $schema->validate( $doc ) }; die $@ if $@; print "VALID\n"; } }
#!/usr/bin/perl -w use strict; use IO::Socket; use File::Slurp; my $xml1 = read_file("C:\\Users\\deadpickle\\Desktop\\UAS\\GRRUVI_1.50 +\\panel\\test.xml"); my $MySocket=new IO::Socket::INET->new(PeerPort=>1234,Proto=>'udp',Pee +rAddr=>'localhost'); while (1) { print $xml1; $MySocket->send($xml1); sleep 5; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: repairing a broken xml using LibXML
by almut (Canon) on Feb 23, 2009 at 01:35 UTC | |
by deadpickle (Pilgrim) on Feb 23, 2009 at 04:10 UTC |