inspect navigate svg

SVG images are popularly used over the web, especially where scalability and quality of images are important. You can inspect, extract, or navigate SVG image elements programmatically with C#. Let us explore the following sections for further details:

SVG Inspection or Navigation in C# - API Installation

Aspose.SVG for .NET API supports creating, editing, or converting SVG files. You can download the DLL file as ZIP from Downloads section. You can also configure it via NuGet Package Manager in Microsoft Visual Studio. Following NuGet installation command can be used to configure it:

PM> Install-Package Aspose.SVG

Inspect SVG Document and its Elements

Several methods in Aspose.SVG for .NET API are based on Element Traversal Specifications as per W3C. You can inspect an SVG file in detail with the following steps:

  1. Load the input SVG file.
  2. Load different elements with DocumentElement object.
  3. Access the value of any property.

The code below explains how to inspect SVG documents and its different elements programmatically using C#:

Extract Information About Specific SVG Elements

An SVG image file consists of several elements under a root element. SVGDocument class exposes different methods to extract information about specific SVG elements, for instance, ParentElement and GetElementsByClassName. Let us follow the steps below for extracting information about specific SVG elements:

  1. Load input SVG image.
  2. Access the DocumentElement attribute.
  3. Read Any Specific Element.

The following code shows how to extract information about a specific SVG element programmatically using C#:

For this demonstration, we have considered working with shapes.svg file.

Navigate SVG using XPath Query

XPath query language is used to select nodes from XML based documents. The following steps elaborate how to navigate SVG image file nodes with XPath Query:

  • Load source SVG file.
  • Evaluate XPath expression.
  • Evaluate and get the next node.

The code below demonstrates how these steps let you navigate SVG nodes programmatically using C# language:

Conclusion

In this article, we have explored how to inspect the SVG file and its elements. Likewise, extracting information from SVG files and navigating SVG nodes using XPath Query is also discussed. Furthermore, you can learn more by reading the Documentation. Feel free to reach out at Free Support Forum. We will be glad to help and guide you!

See Also