Read file with <use> elements

Post questions on how to use or achieve an effect in Inkscape.
User avatar
Micromegas
Posts: 5
Joined: Wed Oct 02, 2019 5:44 am

Read file with <use> elements

Postby Micromegas » Wed Oct 02, 2019 6:41 am

How can I load a file that contains [url href=https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use]use[/url] elements? Inkscape just ignores them.

Sorry if this has already been asked. Searching for this tag unfortunately yields “The following words in your search query were ignored because they are too common words: use.” Entering “<” did not help. I tried “useelement” and “usetag”, too, but of course that gave no results.
Sorry #2: (about repost which didn't get approved, anyway)
Sorry #3: For some reason the BBCode doesn't display correctly. I'll still leave it as is in the hope that that problem gets fixed some day.
Last edited by Micromegas on Wed Oct 02, 2019 6:07 pm, edited 1 time in total.

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Read file with <use> elements

Postby Moini » Wed Oct 02, 2019 8:32 am

Can you append an example file please, and let us know how it's supposed to look, too?
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Read file with <use> elements

Postby Moini » Wed Oct 02, 2019 8:33 am

(I think you're just using what Inkscape calls clones... I don't know of a reason why they wouldn't show up, unless something is maybe wrong with your SVG code)
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
Micromegas
Posts: 5
Joined: Wed Oct 02, 2019 5:44 am

Re: Read file with <use> elements

Postby Micromegas » Wed Oct 02, 2019 12:39 pm

Thank you for your reply. The problem already occurs with the mozilla sample code referenced in my OP - https://developer.mozilla.org/en-US/doc ... lement/use. To focus on the problem I narrowed it down further to just two circles, arriving at the pair:

Code: Select all

<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg">
  <circle id="myCircle" cx="5" cy="5" r="4" stroke="blue"/>
  <use href="#myCircle" x="10" fill="blue"/>
</svg>

Code: Select all

<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg">
  <circle id="myCircle" cx="5" cy="5" r="4" stroke="blue"/>
  <circle cx="15" cy="5" r="4" stroke="blue" fill="blue"/>
</svg>

Inkscape doesn't see the filled circle in the first example. Why not?
Last edited by Micromegas on Wed Oct 02, 2019 5:48 pm, edited 1 time in total.

User avatar
Micromegas
Posts: 5
Joined: Wed Oct 02, 2019 5:44 am

Re: Read file with <use> elements

Postby Micromegas » Wed Oct 02, 2019 1:55 pm

On second thought, I followed Moini's tag line advice and looked at the status bar. On Ctrl-A, it does say
2 objects selected of types Circle, Clone in root. ...

So it's not that Inkscape didn't read the <use> element. But why can't I see the clone? It's probably not outside of the viewBox, as I verified by widening it to "-20 -20 200 100". It's not simply below the circle: If I select that and drag it away (as described at https://designbundles.net/design-school ... n-inkscape) nothing shows up underneath. But when I then Select All, it again selects both, and on View→Zoom→Selection, it becomes obvious that there's nothing at any other position. Maybe the clone is so tightly connected to the original that there's no way to move one without moving the other. My question then becomes: How can I sever that link? Is there a way to do that for all clones in a file at once?

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Read file with <use> elements

Postby Moini » Wed Oct 02, 2019 9:00 pm

Use the correct namespace to make it work. It's xlink:href, not href. See the note at the bottom of the Mozilla article. Contrary to what the Mozilla page suggests, SVG 2 is not official yet. You can request support for it in Inkscape, though, at https://inkscape.org/report .

https://svgwg.org/svg2-draft/single-page.html
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
Micromegas
Posts: 5
Joined: Wed Oct 02, 2019 5:44 am

Re: Read file with <use> elements

Postby Micromegas » Thu Oct 03, 2019 1:32 am

Thank you, that solves the issue for Inkscape.

It does, however, introduce problems for all browsers. Two of them, Firefox and Chrome, at least have the courtesy to tell me what bothers them. The MS products IE and Edge just quietly fail.
Firefox: “XML Parsing Error: prefix not bound to a namespace”
Chrome: “Namespace prefix xlink for href on use is not defined”

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Read file with <use> elements

Postby Moini » Thu Oct 03, 2019 3:08 am

Yes, well. Include the namespace in the SVG tag to fix it.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
Micromegas
Posts: 5
Joined: Wed Oct 02, 2019 5:44 am

Re: Read file with <use> elements

Postby Micromegas » Thu Oct 03, 2019 10:24 am

Thanks! Now it works for all programs.


Return to “Help with using Inkscape”