Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML/SVG SetAttribute Issue xlink:href 1

Status
Not open for further replies.

hungerf5

IS-IT--Management
Sep 17, 2001
36
0
0
US
I'm working on code to generate SVG dynmically via the web. When I try to create an element to display one of the shapes in the <def> section of the SVG file I'm getting unexpected output.

Below I'm trying to create a node called <use> with the following attribute xlink:href.

Code:
svgElem = SvgXml.CreateElement("use", "[URL unfurl="true"]http://www.w3.org/2000/svg");[/URL]
svgElem.SetAttribute("xlink:href", "#" + sheetName);
RootNode.ChildNodes[1].FirstChild.AppendChild(svgElem);

XML Output
Code:
<?xml version="1.0" standalone="yes"?>
<svg width="800" height="600" xmlns="[URL unfurl="true"]http://www.w3.org/2000/svg">[/URL]
  <def>
    <rect id="13-81X76.5X3.5" x="0" y="0" widht="800" height="600" style="fill:none;stroke:rgb(0,0,255);stroke-width:.05" />
  </def>
  <g transform="translate(20, 585)">
    <g transform="scale(0.95, -0.95)">
      <use href="#13-81X76.5X3.5" />
    </g>
  </g>
</svg>

Notice the code is outputting:
Code:
<use href="#13-81X76.5X3.5" />

I expected to see:
Code:
<use xlink:href="#13-81X76.5X3.5" />

Why is this happening and how can I get the resluts necessary for the SVG to work properly?

--Rick
 
I found a solution but I'm not sure I understand it?

Here code that get the results I'm looking for:
Code:
svgElem = SvgXml.CreateElement("use", "[URL unfurl="true"]http://www.w3.org/2000/svg");[/URL]
svgElem.SetAttributeNode("href", "[URL unfurl="true"]http://www.w3.org/1999/xlink");[/URL]
svgElem.Attributes["href"].Value = "#" + sheetName;
svgElem.Attributes["href"].Prefix = "xlink";
RootNode.ChildNodes[1].FirstChild.AppendChild(svgElem);

Here is the XML:
Code:
<?xml version="1.0" standalone="yes"?>
<svg width="800" height="600" xmlns="[URL unfurl="true"]http://www.w3.org/2000/svg">[/URL]
  <def>
    <rect id="13-81X76.5X3.5" x="0" y="0" widht="800" height="600" style="fill:none;stroke:rgb(0,0,255);stroke-width:.05" />
  </def>
  <g transform="translate(20, 585)">
    <g transform="scale(0.95, -0.95)">
      <use xlink:href="#13-81X76.5X3.5" xmlns:xlink="[URL unfurl="true"]http://www.w3.org/1999/xlink"[/URL] />
    </g>
  </g>
</svg>

--Rick
 
Wild. You get a star for solving your own problem.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Yeah it only took me half a day of goggling and piecing together bits of information from here ant there...

Ah, the joys of developing when you don't know what you’re doing...

How can I give myself a star? ;)

--Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top