wi2fish wrote:

> Hi everyone,
>
> I should clarify that I am at the beginning of learning SVG and have
> to fight with it's specialities. There are some things that I like
> about SVG.
>
> For instance, verbosity: You have the DOCTYPE and PUBLIC and xmlns and
> script tags and script tag types and all that stuff. And if you get it
> wrong, then your browser shows nothing. If we only want to use SVG 1.1
> and JavaScript, why the confusion? I found out it can be much easier
> with ASV 3+6. Opera doesn't show much (only the Text itself, as if it
> were xml), and I never got Mozilla's SVG to show any SVG. I'm too lazy
> to try out all possible combinations, I know. But I'd like the browser
> to at least try to show something. I don't like ASV, but it does well
> there.

my simple svg document template looks like this:

<?xml version="1.0" ?>
 <svg   xmlns="http://www.w3.org/2000/svg";  
xmlns:xlink="http://www.w3.org/1999/xlink";>

</svg>

this way it should work in any svg viewer. you dont need a doctype ;)

>
> Another one, clarity: You look at some code and you think you
> perfectly know what it's doing. Right?
>
> For instance, you'll immediately know what this does:
>
> nodes.es:
>
> function replacetext(evt) {
>     nodes=window.svgDocument.getElementById("sampletext").childNodes;

make that:
svgns="http://www.w3.org/2000/svg";
 
nodes=window.svgDocument.getElementById("sampletext").getElementsByTagNameNS(svgns,"tspan");
 


>     len=nodes.length;
>
>     for (i=0; i<len; i++)
>       nodes.item(i).data="node "+i;

change to: nodes.item(i).firstChild.data="node "+i;

> }
>
> nodes.svg:
>
> <?xml version="1.0"?>
> <svg onload="replacetext(evt)" >
>     <script xlink:href="nodes.es" />
>     <text id="sampletext" y="20">
>       <tspan x="5" dy="1em">line 1</tspan>
>       <tspan x="5" dy="1em">line 2</tspan>
>       <tspan x="5" dy="1em">line 3</tspan>
>     </text>
> </svg>
>
>
> (By the way, I wanted to put this into one file instead of two, but
> then I would have had to know this strange CDATA syntax... Who on
> earth invented that?)

i dont know who invented it, but its quite simple <![CDATA[ //some 
content  ]]> you dont really need CDATA sections,
you can as well just replace "<" with &lt; and ">" with &gt;
sofor example your loop may look like this, when used inside <script> 
without CDATA
for (i=0; i&lt;len; i++)

>
> You'll expect that the script would change the lines
>
> line 1
> line 2
> line 3
>
> into the lines
>
> node 1
> node 2
> node 3
>
> and you'll expect that len is 3, right? No. that's what it shows:
>
> node 0
> line 1node 2
> line 2node 4
> line 3node 6
>
> and len will be 7 in the end. Note the extra node 0 and the
> concatenated old and new text of the tspan's.

the reason for this behavior is that there are many node types in xml.
there are:

    ELEMENT_NODE                   = 1;
    ATTRIBUTE_NODE                 = 2;
    TEXT_NODE                      = 3;
    CDATA_SECTION_NODE             = 4;
    ENTITY_REFERENCE_NODE          = 5;
    ENTITY_NODE                    = 6;
    PROCESSING_INSTRUCTION_NODE    = 7;
    COMMENT_NODE                   = 8;
    DOCUMENT_NODE                  = 9;
    DOCUMENT_TYPE_NODE             = 10;
    DOCUMENT_FRAGMENT_NODE         = 11;
    NOTATION_NODE                  = 12;



and childNodes() gets all nodeTypes,not only element nodes
try this:

    for (i=0; i<len; i++)
      alert(nodes.item(i).nodeType)
}

 in yor original example, and you ll get a sequence of altering 1 and 3 
that means you are iterating over element nodes and text nodes.

hope that helps
Holger

p.s.: the complete filemaylook something like this:


<?xml version="1.0"?>
<svg onload="replacetext(evt)" >
    <script><![CDATA[
    function replacetext(evt) {
    svgns="http://www.w3.org/2000/svg";
    
nodes=window.svgDocument.getElementById("sampletext").getElementsByTagNameNS(svgns,"tspan")
    len=nodes.length;

    for (i=0; i<len; i++)
      nodes.item(i).firstChild.data="node "+i;
}
    ]]></script>
    <text id="sampletext" y="20">
    <!-- test -->
      <tspan x="5" dy="1em">line 1</tspan>
      <tspan x="5" dy="1em">line 2</tspan>
      <tspan x="5" dy="1em">line 3</tspan>
    </text>
</svg>


-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
---- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to