Re: multiple siblings, using tDOM to generate XML




Hello,

A simple way to generate XML is the following:

proc map { str } {
set mapTEXT2XML [list > "&gt;" < "&lt;" & "&amp;" \" "&quot;" ' "&apos;"]
return [string map $mapTEXT2XML $str]
}


set xml "<a><b>[map $mytext]</b>
<another_tag
>[map $more_text]</another_tag>
</a>"

set doc [dom parse $xml]

The only trick is to leave the newlines either inside the
construction <tag > or between tags that have no additional text.

Regards,


Ramon Ribó

En Wed, 29 Nov 2006 20:36:38 +0100, jkj <kevin@xxxxxxxxxx> escribió:


I'm wanting to use tDOM to generate an XML document but am having
difficulties with multiple siblings. These four lines are my desired
output:
<InformationURL>
<Name/>
<URL/>
</InformationURL>


...ok, I took the tutorial example and broke it down more step-by-step
and can see that the problem is a lack of newlines? - whatever that
translates into in Tcl. For example:

...a failure [title { } and description { } are on the same line]:
% $root appendFromScript {
channel {
title { } description { }
}
}
Invalid attribute name ' '

...the format that eventually passes:
% $root appendFromScript {
channel {
title { }
description { }
}
}
domNode0x8e678bc

...somehow I can't imagine that I have to insert newlines into a nested
set of these commands, so I would have thought that something like this
would work:
$root appendFromScript { [channel { [title { } ] [ description { } ] }
] }

...doesn't the [ command ] execute the command and return the value?
why the need for newlines?...

Thanks,
-Kevin




--
Compass Ing. y Sistemas Dr. Ramon Ribo
http://www.compassis.com ramsan@xxxxxxxxxxxxx
c/ Tuset, 8 7-2 tel. +34 93 218 19 89
08006 Barcelona, Spain fax. +34 93 396 97 46
.



Relevant Pages

  • Re: tclsoap illegal characters
    ... Mapping for XML is not much more than: ... proc map { ... return [string map $mapTEXT2XML $str] ... Encoding such special characters (which it seems you've already ...
    (comp.lang.tcl)
  • Re: REXML memory consumption
    ... I created a test that consisted of feeding 10 xml ... I would think that memory usage ... Is there something wrong with my understanding of Ruby or does REXML ... str << line ...
    (comp.lang.ruby)
  • Re: REXML memory consumption
    ... I would think that memory usage ... Is there something wrong with my understanding of Ruby or does REXML ... str << line ... No need to read the whole file into a large string before it is parsed as XML. ...
    (comp.lang.ruby)
  • Re: How to check if a string is an XML before calling LoadXML(str)
    ... I am new to C# so I might be asking some silly questions. ... if the str is not XML then I would like to do something else instead of being ... >> return but only throw exception if str is not XML document. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Select Into With SELECT FROM for xml auto
    ... propagate since you will be able to insert and assign FOR XML expressions ... >> SET nocount ON DECLARE @str varchar ...
    (microsoft.public.sqlserver.xml)