xmi

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package xmi reads UML 2.x models serialized as XMI, as SysML v1 tools export them, into a generic element tree with the stereotypes applied to it.

The reader is deliberately tolerant of the serialization's dialect: the UML, XMI and profile namespaces differ between the OMG normative XMI and the Eclipse UML2 serialization Papyrus writes, so elements are classified by the local part of their xmi:type and stereotype applications by the local part of their element name. A zip archive holding the model, such as a MagicDraw .mdzip project, is opened in place and its model entries read as one document.

The tree carries no UML semantics of its own; internal/core/migrate interprets it as a SysML v1 model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	// ID is the xmi:id, or the href for a proxy of an external element.
	ID string
	// Type is the local name of the xmi:type, such as "Class" or "Property".
	// A proxy carries the type its reference declared, or "".
	Type string
	// Role is the XML element name that owns this element in its parent, such
	// as "packagedElement" or "ownedAttribute"; empty for a root.
	Role string
	// Name is the element's name attribute; a proxy takes the href fragment
	// when it reads as a name.
	Name string
	// Href is set on a proxy for an element of another document.
	Href string
	// Attrs holds the XML attributes other than xmi:id and xmi:type, keyed by
	// local name; references appear as their raw id text.
	Attrs map[string]string
	// Text is the element's character content, which stereotype tag values
	// and opaque expression bodies are written as.
	Text     string
	Parent   *Element
	Children []*Element
	// Stereotypes are the stereotype applications whose base is this element.
	Stereotypes []*Stereotype
	// contains filtered or unexported fields
}

Element is one node of the model: a UML element with an xmi:id, or a proxy for an element in another document that an href points at.

func (*Element) HasStereotype

func (e *Element) HasStereotype(names ...string) bool

HasStereotype reports whether any of the named stereotypes applies to e.

func (*Element) IsProxy

func (e *Element) IsProxy() bool

IsProxy reports whether e stands for an element of another document.

func (*Element) Owned

func (e *Element) Owned(role string) []*Element

Owned returns the children of e in a role, such as its "ownedAttribute"s.

func (*Element) Path

func (e *Element) Path() []string

Path returns the names from the root to e, for diagnostics; anonymous elements contribute their type in angle brackets.

func (*Element) Stereotype

func (e *Element) Stereotype(name string) *Stereotype

Stereotype returns e's application of the named stereotype, or nil.

type Extension

type Extension struct {
	// Extender is the tool named by the block's extender attribute.
	Extender string
	// Owner is the element the block sits in; nil at the document root.
	Owner *Element
	// Elements are the xmi:type and name of every typed element inside, e.g. "uml:Diagram Vehicle BDD".
	Elements []ExtensionElement
}

Extension records one skipped xmi:Extension: who wrote it and what it held.

type ExtensionElement

type ExtensionElement struct {
	ID, Type, Name string
}

ExtensionElement is one typed element inside a skipped extension.

type Model

type Model struct {
	// Roots are the top-level UML elements, in document order.
	Roots []*Element
	// Stereotypes are every stereotype application, in document order.
	Stereotypes []*Stereotype
	// Exporter records the xmi:Documentation exporter, when the document names one.
	Exporter string
	// Extensions are the tool-private xmi:Extension blocks that were skipped.
	Extensions []Extension
	// contains filtered or unexported fields
}

Model is one document, or one archive's documents read as one.

func Parse

func Parse(data []byte) (*Model, error)

Parse reads an XMI document, or a zip archive (such as a MagicDraw .mdzip) holding one or more, into a Model.

func (*Model) Lookup

func (m *Model) Lookup(id string) *Element

Lookup resolves an xmi:id, or an href of an element another document holds, to its element; nil when the document defines neither.

func (*Model) Ref

func (m *Model) Ref(e *Element, role string) *Element

Ref returns the first element a role refers to, or nil.

func (*Model) Refs

func (m *Model) Refs(e *Element, role string) []*Element

Refs returns the elements a role of e refers to: the ids in the attribute of that name (space-separated, as XMI writes multi-valued references) and the child elements of that name carrying xmi:idref or href. Unresolvable ids are dropped (Unresolved lists them); an href yields a proxy element.

func (*Model) Unresolved

func (m *Model) Unresolved(e *Element, role string) []string

Unresolved returns the ids a role of e refers to that no read document defines, so a caller can tell a complete reference list from a dangling one.

type Stereotype

type Stereotype struct {
	ID string
	// Name is the stereotype's local name, such as "Block" or "Requirement".
	Name string
	// Namespace is the XML namespace the profile was serialized under.
	Namespace string
	// BaseID is the value of the base_* attribute; Base resolves it.
	BaseID string
	Base   *Element
	// Tags holds the tagged values: attributes other than xmi:* and base_*, and
	// child elements as their text or idref, keyed by tag name. A multi-valued
	// tag lists each value.
	Tags map[string][]string
}

Stereotype is one stereotype application: an element outside the UML model whose base_* attribute names the element it extends.

func (*Stereotype) Tag

func (s *Stereotype) Tag(name string) string

Tag returns the first value of a tag, or "".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL