RE: :Writer beginner problems

From: Rob Hanson (rhanson_at_aptegrity.com)
Date: 02/03/04


To: 'KEVIN ZEMBOWER' <KZEMBOWE@jhuccp.org>, beginners@perl.org
Date: Tue, 3 Feb 2004 12:46:26 -0500 


> <?xml version="1.0" encoding="ISO-8859-1"?>
> <docnum>PIP 189165</docnum>
> <greeting class="simple">Hello, world!</greeting>
> ...
> Attempt to insert start tag after close of document
> element at ./test.pl line 11

A rule of XML is that there MAY ONLY BE ONE ROOT ELEMENT. You have two.

You need to put <docnum> and <greeting> inside a single element. The
following would be well-formed XML.

<?xml version="1.0" encoding="ISO-8859-1"?>
<rootTag>
  <docnum>PIP 189165</docnum>
  <greeting class="simple">Hello, world!</greeting>
</rootTag>

Rob

-----Original Message-----
From: KEVIN ZEMBOWER [mailto:KZEMBOWE@jhuccp.org]
Sent: Tuesday, February 03, 2004 12:41 PM
To: beginners@perl.org
Subject: XML::Writer beginner problems

Hope it's okay to write to this group regarding beginner problems with
XML::Writer. I'm a beginner both to XML in general, and XML::Writer in
particular.

I'm trying to run this program:
============================
#! /usr/bin/perl

use XML::Writer;

my $writer = new XML::Writer(DATA_MODE => 1,
                             DATA_INDENT => 3,
                             UNSAFE =>1);

$writer->xmlDecl("ISO-8859-1");

$writer->dataElement("docnum", "PIP 189165");
$writer->startTag("greeting",
                  "class" => "simple");
$writer->characters("Hello, world!");
$writer->endTag("greeting");

$writer->end();
============================
When I do, I get the output I think I want:
kevinz@www:~/POPLINE_XML$ ./test.pl

<?xml version="1.0" encoding="ISO-8859-1"?>

<docnum>PIP 189165</docnum>
<greeting class="simple">Hello, world!</greeting>
kevinz@www:~/POPLINE_XML$

This output looks like valid XML to me. I don't see any problems with it.

However, when I remove the UNSAFE and change the third line to:
my $writer = new XML::Writer(DATA_MODE => 1,
                             DATA_INDENT => 3);

I get this output:
kevinz@www:~/POPLINE_XML$ ./test.pl
<?xml version="1.0" encoding="ISO-8859-1"?>

Attempt to insert start tag after close of document element at ./test.pl
line 11
<docnum>PIP 189165</docnum>kevinz@www:~/POPLINE_XML$

I don't understand what I'm doing wrong to cause XML::Writer to complain. Do
I not understand XML correctly?

Thanks for your thoughts and suggestions.

-Kevin Zembower

-----
E. Kevin Zembower
Unix Administrator
Johns Hopkins University/Center for Communications Programs
111 Market Place, Suite 310
Baltimore, MD 21202
410-659-6139

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Relevant Pages

  • Re: Editing XML
    ... I wonder how text and child nodes are distinguished in the XML text. ... The first is the processing instruction, which you'll typically ignore in XSLT. ... THe next is the element node named "tag" and the last is the text node. ... There is always exactly one root element in a valid XML document. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Editing XML
    ... THe next is the element node named "tag" and the last is the text node. ... which defines the end of the same element node that <xml> began. ... Most probably it's the implementation of MSXML, where closing tags seem to translate into their own nodes, with the name and type of the opening tag, they only don't have child nodes and attributes. ... There is always exactly one root element in a valid XML document. ...
    (comp.lang.pascal.delphi.misc)
  • Re: How can I ensure that I always have a list?
    ... tdom is an XML parsing extension for Tcl. ... # Match one tag. ... # quotes, ... # key/value pair) for further processing the next time we go ...
    (comp.lang.tcl)
  • Re: How can I ensure that I always have a list?
    ... tdom is an XML parsing extension for Tcl. ... # Match one tag. ... # quotes, ... # key/value pair) for further processing the next time we go ...
    (comp.lang.tcl)
  • Re: ruby html (or xhtml) forms class...
    ... xx is a library designed to extend ruby objects with html, xhtml, and xml ... xml or xhtml as clean looking and natural as ruby it self. ... attributes may be passed to any tag method as either symbol or string. ...
    (comp.lang.ruby)