You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Jeff Abernathy <je...@asolutions.com> on 2007/05/23 20:35:43 UTC

The attribute "xlink:href" of the element is required

I'm having trouble inserting a "use" element into a Document. This is a basic drawing application that has a "stamp" tool, and for this stamp I'm using a group. When I try to append the use element to the document I get the error "The attribute "xlink:href" of the element <use> is required". The xlink:href attribute is most certainly present, here is the code that creates the element:

final Element element = getElement();
element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, X_ATTRIBUTE_NAME, "" + origin.getX());
element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, Y_ATTRIBUTE_NAME, "" + origin.getY());
element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, "xlink:href", GROUP_NAME);
.
.
.
document.getDocumentElement().appendChild(element);


If I save the document to the file system after inserting a few of these stamps, and then open it, the stamps render without any problems. Could there be something that is happening under the covers in the save/open process? What am I missing here? Here is how the Document object is saved to the file system (how we convert it to a string):

DOMSource domSource = new DOMSource(node);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
try {
     Transformer transformer = tf.newTransformer();
     transformer.transform(domSource, result);
     return writer.toString();
}


and here is how a file is opened (converted from a string to a Document object):

SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName());
return factory.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, new StringReader(svgXmlDocumentAsString));


Any help would be greatly appreciated!

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: The attribute "xlink:href" of the element is required

Posted by Archie Cobbs <ar...@awarix.com>.
On 5/23/07, Jeff Abernathy <je...@asolutions.com> wrote:
> I'm having trouble inserting a "use" element into a Document. This is a basic drawing application that has a "stamp" tool, and for this stamp I'm using a group. When I try to append the use element to the document I get the error "The attribute "xlink:href" of the element <use> is required". The xlink:href attribute is most certainly present, here is the code that creates the element:
>
> final Element element = getElement();
> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, X_ATTRIBUTE_NAME, "" + origin.getX());
> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, Y_ATTRIBUTE_NAME, "" + origin.getY());
> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, "xlink:href", GROUP_NAME);

A couple of possibly useful ideas..

- Make sure "xmlns:xlink" is defined appropriately on this or a higher node
- Use org.apache.batik.util.XMLConstants.XLINK_NAMESPACE_URI to be sure you
  don't have a typo. Also lots of constants are in SVGConstants (same package).
- "x" and "y" should be in the null namespace.. perhaps your stamp is appearing
  at location (0, 0) which is "off screen"?

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: The attribute "xlink:href" of the element is required

Posted by Randy Kunkee <ra...@randallkunkee.com>.
Hello Jeff,

Try element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, "href",  
GROUP_NAME);

Randy

On Jun 2, 2007, at 6:49 AM, thomas.deweese@kodak.com wrote:

> Hi Jeff,
>
> Jeff Abernathy <je...@asolutions.com> wrote on 05/23/2007
> 02:35:43 PM:
>
>> I'm having trouble inserting a "use" element into a Document. This
>> is a basic drawing application that has a "stamp" tool, and for this
>> stamp I'm using a group. When I try to append the use element to the
>> document I get the error "The attribute "xlink:href" of the element
>> <use> is required". The xlink:href attribute is most certainly
>> present, here is the code that creates the element:
>
>> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, "xlink:
>> href", GROUP_NAME);
>
>     You will also get this error if the value of the
> xlink:href attribute is the empty string.  Is it possible that
> GROUP_NAME isn't getting set for some reason?
>
>>
>> final Element element = getElement();
>> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS,
>> X_ATTRIBUTE_NAME, "" + origin.getX());
>> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS,
>> Y_ATTRIBUTE_NAME, "" + origin.getY());
>
>     Also as someone else pointed out the 'x' and 'y' attributes
> on the use element are not in the xlink namespace, they are in
> the 'null' namespace.
>
>> If I save the document to the file system after inserting a few of
>> these stamps, and then open it, the stamps render without any
>> problems. Could there be something that is happening under the
>> covers in the save/open process?
>
>    There is lots that happens during the save/restore processes
> in particular the namespaces are rebound based on the prefixes.
> So if your constant for the XLINK NS was wrong this is the behavior
> you would see.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users- 
> help@xmlgraphics.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: The attribute "xlink:href" of the element is required

Posted by th...@kodak.com.
Hi Jeff,

Jeff Abernathy <je...@asolutions.com> wrote on 05/23/2007 
02:35:43 PM:

> I'm having trouble inserting a "use" element into a Document. This 
> is a basic drawing application that has a "stamp" tool, and for this
> stamp I'm using a group. When I try to append the use element to the
> document I get the error "The attribute "xlink:href" of the element 
> <use> is required". The xlink:href attribute is most certainly 
> present, here is the code that creates the element:

> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, "xlink:
> href", GROUP_NAME);

    You will also get this error if the value of the
xlink:href attribute is the empty string.  Is it possible that
GROUP_NAME isn't getting set for some reason?

> 
> final Element element = getElement();
> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, 
> X_ATTRIBUTE_NAME, "" + origin.getX());
> element.setAttributeNS(SketchPadConstants.SVG_XLINK_NS, 
> Y_ATTRIBUTE_NAME, "" + origin.getY());

    Also as someone else pointed out the 'x' and 'y' attributes
on the use element are not in the xlink namespace, they are in
the 'null' namespace.

> If I save the document to the file system after inserting a few of 
> these stamps, and then open it, the stamps render without any 
> problems. Could there be something that is happening under the 
> covers in the save/open process?

   There is lots that happens during the save/restore processes
in particular the namespaces are rebound based on the prefixes.
So if your constant for the XLINK NS was wrong this is the behavior
you would see.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org