LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XML Parser Memory leak


@BertMcMahan wrote:

@thomas-allibe wrote:

For my use case the built in parser is enough, for now. It's slow for a XML parser, but I only load 1 or 2 simple SVGs on a panel. I don't even bother caching the icon, which would be a good improvement. I went for the easiest implementation.


As an alternative to parsing XML entirely, I think I could just perform string manipulation.
I only do 2 simple things on my SVGs:

- set "width" and "height" attributes on the "svg" tag.

- set "fill" and "fill-opacity" to the "style" attribute of all the "path" tags.


I'm no expert here but I'd be careful. You couldn't just search for the words, as you'd need to ensure that "fill" is within a "path" tag... which sounds like XML parsing to me 🙂

 

And don't forget, you can't parse XML with regex. 


Yes, when I said "As an alternative to parsing XML entirely, I think I could just perform string manipulation." I meant: instead of using the native XML parser which, I guess, creates a tree representation of the whole XML file structure, I can just search for "svg" and "path" opening tags and then edit the appropriate attributes, all while keeping the XML as a string. Which indeed sounds like parsing 😄.

0 Kudos
Message 11 of 13
(145 Views)

Oh yeah I mean, I understood what you meant... it's just that you can't simply search for "path" because other elements may also have that word in there. You might be able to find "svg" then look for the next instance of "width", assuming there hasn't been any < or > characters.

 

By the way, I glanced at VIPM and someone has an SVG library: https://www.vipm.io/package/dataflow_g_lib_g_image/

 

If it doesn't do what you need it to, it might give you some ideas.

0 Kudos
Message 12 of 13
(117 Views)

@BertMcMahan wrote:

Oh yeah I mean, I understood what you meant... it's just that you can't simply search for "path" because other elements may also have that word in there. You might be able to find "svg" then look for the next instance of "width", assuming there hasn't been any < or > characters.

 

By the way, I glanced at VIPM and someone has an SVG library: https://www.vipm.io/package/dataflow_g_lib_g_image/

 

If it doesn't do what you need it to, it might give you some ideas.


Actually I use this exact library to rasterize my SVGs after setting the attributes.

thomasallibe_0-1787032229629.pngthomasallibe_0-1787032229629.png

Before displaying the image, I center it and blend a solid background to it (which is a bit slow because it's all CPU work).
The blend operation is done in order to get a smooth image, but I discovered later "\vi.lib\picture\PNG\Draw Flattened Blended Pixmap.vi" here: Officially Support and Improve Alpha in Picture Controls - NI Community
Which is way faster and allows for all transparency values (against only opaque or fully transparent in my implementation). By setting the picture control transparent, it will use the pane color for background (in my current implementation, I need to make sure I use the same color for both picture background and pane).

 

This could allow to make front panel overlays, to show contextual help for example. But some benchmark needs to be done to know if we can edit the SVG attribute, rasterize it and then update the picture control fast enough.

Message 13 of 13
(90 Views)