Struct autosar_data::Element
source · [−]pub struct Element(_);Expand description
An arxml element
This is actually a wrapper type which provides all the necessary manipulation functions. The actual element data is held behind Arc<Mutex<>>.
Implementations
sourceimpl Element
impl Element
sourcepub fn parent(&self) -> Result<Option<Element>, AutosarDataError>
pub fn parent(&self) -> Result<Option<Element>, AutosarDataError>
Get the parent element of the current element
Returns None if the current element is the root, or if it has been deleted from the element hierarchy
Example
if let Some(parent) = element.parent()? {
// ...
}Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
sourcepub fn element_name(&self) -> ElementName
pub fn element_name(&self) -> ElementName
Get the ElementName of the element
Example
let element = file.root_element();
let element_name = element.element_name();
assert_eq!(element_name, ElementName::Autosar);sourcepub fn element_type(&self) -> ElementType
pub fn element_type(&self) -> ElementType
Get the ElementType of the element
The ElementType is needed in order to call methods from the autosar-data-specification crate
Example
let element_type = element.element_type();sourcepub fn item_name(&self) -> Option<String>
pub fn item_name(&self) -> Option<String>
Get the name of an identifiable element
An identifiable element has a <SHORT-NAME> sub element and can be referenced using an autosar path.
If the element is not identifiable, this function returns None
Example
if let Some(item_name) = element.item_name() {
// ...
}sourcepub fn set_item_name(&self, new_name: &str) -> Result<(), AutosarDataError>
pub fn set_item_name(&self, new_name: &str) -> Result<(), AutosarDataError>
Set the item name of this element
This operation will update all references pointing to the element or its sub-elements so that they remain valid.
Example
element.set_item_name("NewName");Note
In order to rename an element without updating any references, do this instead:
if let Some(short_name) = element.get_sub_element(ElementName::ShortName) {
short_name.set_character_data(CharacterData::String("the_new_name".to_string()));
}Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::ItemNameRequired this function was called for an element which is not identifiable
sourcepub fn is_identifiable(&self) -> bool
pub fn is_identifiable(&self) -> bool
Returns true if the element is identifiable
In order to be identifiable, the specification must require a SHORT-NAME sub-element and the SHORT-NAME must actually be present.
Example
if element.is_identifiable() {
// ...
}sourcepub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
Returns true if the element should contain a referenct to another element
The function does not check if the reference is valid
Example
if element.is_reference() {
// ex: element.set_reference_target(...)
}sourcepub fn path(&self) -> Result<String, AutosarDataError>
pub fn path(&self) -> Result<String, AutosarDataError>
Get the Autosar path of an identifiable element
Example
let path = element.path()?;Possible Errors
- AutosarDataError::ItemDeleted: Th ecurrent element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::ElementNotIdentifiable: The current element is not identifiable, so it has no Autosar path
sourcepub fn file(&self) -> Result<ArxmlFile, AutosarDataError>
pub fn file(&self) -> Result<ArxmlFile, AutosarDataError>
Get a reference to the ArxmlFile containing the current element
Example
let file = element.file()?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
sourcepub fn content_type(&self) -> ContentType
pub fn content_type(&self) -> ContentType
Get the ContentType of the current element
Example
if element.content_type() == ContentType::CharacterData {
// ...
}sourcepub fn create_sub_element(
&self,
element_name: ElementName
) -> Result<Element, AutosarDataError>
pub fn create_sub_element(
&self,
element_name: ElementName
) -> Result<Element, AutosarDataError>
Create a sub element at a suitable insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist. It is not possible to create named sub elements with this function; use create_named_sub_element() for that instead.
Example
let element = file.root_element().create_sub_element(ElementName::ArPackages)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::ItemNameRequired: The sub element requires an item name, so you must use create_named_sub_element().
sourcepub fn create_sub_element_at(
&self,
element_name: ElementName,
position: usize
) -> Result<Element, AutosarDataError>
pub fn create_sub_element_at(
&self,
element_name: ElementName,
position: usize
) -> Result<Element, AutosarDataError>
Create a sub element at the specified insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist. It is not possible to create named sub elements with this function; use create_named_sub_element_at() for that instead.
The specified insertion position will be compared to the range of valid insertion positions; if it falls outside that range then the function fails.
Example
let element = file.root_element().create_sub_element_at(ElementName::ArPackages, 0)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::ItemNameRequired: The sub element requires an item name, so you must use create_named_sub_element_at().
- AutosarDataError::InvalidPosition: This sub element cannot be created at the requested position
sourcepub fn create_named_sub_element(
&self,
element_name: ElementName,
item_name: &str
) -> Result<Element, AutosarDataError>
pub fn create_named_sub_element(
&self,
element_name: ElementName,
item_name: &str
) -> Result<Element, AutosarDataError>
Create a named/identifiable sub element at a suitable insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist.
This method can only be used to create identifiable sub elements.
Example
let pkgs_element = file.root_element().create_sub_element(ElementName::ArPackages)?;
let element = pkgs_element.create_named_sub_element(ElementName::ArPackage, "Package")?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::ElementNotIdentifiable: The sub element does not have an item name, so you must use create_sub_element() instead.
sourcepub fn create_named_sub_element_at(
&self,
element_name: ElementName,
item_name: &str,
position: usize
) -> Result<Element, AutosarDataError>
pub fn create_named_sub_element_at(
&self,
element_name: ElementName,
item_name: &str,
position: usize
) -> Result<Element, AutosarDataError>
Create a named/identifiable sub element at the specified insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist. The specified insertion position will be compared to the range of valid insertion positions; if it falls outside that range then the function fails.
This method can only be used to create identifiable sub elements.
Example
let pkgs_element = file.root_element().create_sub_element(ElementName::ArPackages)?;
let element = pkgs_element.create_named_sub_element_at(ElementName::ArPackage, "Package", 0)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::ElementNotIdentifiable: The sub element does not have an item name, so you must use create_sub_element() instead.
- AutosarDataError::InvalidPosition: This sub element cannot be created at the requested position.
sourcepub fn create_copied_sub_element(
&self,
other: &Element
) -> Result<Element, AutosarDataError>
pub fn create_copied_sub_element(
&self,
other: &Element
) -> Result<Element, AutosarDataError>
Create a deep copy of the given element and insert it as a sub-element
The other element must be a permissible sub-element in this element and not conflict with any existing sub element. The other element can originate from any loaded AutosarProject, it does not have to originate from the same project or file as the current element.
The AutosarVersion of the other element might differ from the version of the current file; in this case a partial copy will be performed that omits all incompatible elements.
If the copied element is identifiable, then the item name might be extended with a numerical suffix, if one is required in order to make the name unique. For example: An identifiable element “Foo” already exists at the same path; the copied identifiable element will be renamed to “Foo_1”.
If the copied element or the hierarchy of elements under it contain any references, then these will need to be adjusted manually after copying.
Example
let other_element = project.get_element_by_path("/Package/Path").unwrap();
let element = base.create_copied_sub_element(&other_element)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
sourcepub fn create_copied_sub_element_at(
&self,
other: &Element,
position: usize
) -> Result<Element, AutosarDataError>
pub fn create_copied_sub_element_at(
&self,
other: &Element,
position: usize
) -> Result<Element, AutosarDataError>
Create a deep copy of the given element and insert it as a sub-element at the given position
The other element must be a permissible sub-element in this element and not conflict with any existing sub element. The other element can originate from any loaded AutosarProject, it does not have to originate from the same project or file as the current element.
The AutosarVersion of the other element might differ from the version of the current file; in this case a partial copy will be performed that omits all incompatible elements.
If the copied element is identifiable, then the item name might be extended with a numerical suffix, if one is required in order to make the name unique. For example: An identifiable element “Foo” already exists at the same path; the copied identifiable element will be renamed to “Foo_1”.
If the copied element or the hierarchy of elements under it contain any references, then these will need to be adjusted manually after copying.
Example
let other_element = project.get_element_by_path("/Package/Path").unwrap();
let element = base.create_copied_sub_element_at(&other_element, 0)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::InvalidPosition: This sub element cannot be created at the requested position.
sourcepub fn move_element_here(
&self,
move_element: &Element
) -> Result<Element, AutosarDataError>
pub fn move_element_here(
&self,
move_element: &Element
) -> Result<Element, AutosarDataError>
Take an element from it’s current location and place it in this element as a sub element
The moved element can be taken from anywhere - even from a different arxml document that is not part of the same AutosarProject
Restrictions:
- The element must have a compatible element type. If it could not have been created here, then it can’t be moved either.
- The origin document of the element must have exactly the same AutosarVersion as the destination.
Example
let other_element = project.get_element_by_path("/Package/Path").unwrap();
let element = base.move_element_here(&other_element)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::VersionIncompatible: The Autosar versions of the source and destination are different
- AutosarDataError::ForbiddenMoveToSubElement: The destination is a sub element of the source. Moving here is not possible
sourcepub fn move_element_here_at(
&self,
move_element: &Element,
position: usize
) -> Result<Element, AutosarDataError>
pub fn move_element_here_at(
&self,
move_element: &Element,
position: usize
) -> Result<Element, AutosarDataError>
Take an element from it’s current location and place it at the given position in this element as a sub element
The moved element can be taken from anywhere - even from a different arxml document that is not part of the same AutosarProject
Restrictions:
- The element must have a compatible element type. If it could not have been created here, then it can’t be moved either.
- The origin document of the element must have exactly the same AutosarVersion as the destination.
Example
let other_element = project.get_element_by_path("/Package/Path").unwrap();
let element = base.move_element_here_at(&other_element, 0)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content type CharacterData.
- AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.
- AutosarDataError::InvalidSubElement: The ElementName is not a valid sub element according to the specification.
- AutosarDataError::VersionIncompatible: The Autosar versions of the source and destination are different
- AutosarDataError::ForbiddenMoveToSubElement: The destination is a sub element of the source. Moving here is not possible
- AutosarDataError::InvalidPosition: This sub element cannot be created at the requested position.
sourcepub fn remove_sub_element(
&self,
sub_element: Element
) -> Result<(), AutosarDataError>
pub fn remove_sub_element(
&self,
sub_element: Element
) -> Result<(), AutosarDataError>
Remove the sub element sub_element
The sub_element will be unlinked from the hierarchy of elements. All of the sub-sub-elements nested under the removed element will also be recusively removed.
Since all elements are reference counted, they might not be deallocated immediately, however they do become invalid and unusable immediately.
Example
let packages = file.root_element().create_sub_element(ElementName::ArPackages)?;
file.root_element().remove_sub_element(packages)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::ElementNotFound: The sub element was not found in this element
- AutosarDataError::ShortNameRemovalForbidden: It is not permitted to remove the SHORT-NAME of identifiable elements since this would result in invalid data
sourcepub fn set_reference_target(
&self,
target: &Element
) -> Result<(), AutosarDataError>
pub fn set_reference_target(
&self,
target: &Element
) -> Result<(), AutosarDataError>
Set the reference target for the element to target
When the reference is updated, the DEST attribute is also updated to match the referenced element. The current element must be a reference element, otherwise the function fails.
Example
let cluster_element = elements.create_named_sub_element(ElementName::CanCluster, "Cluster")?;
ref_element.set_reference_target(&cluster_element)?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::NotReferenceElement: The current element is not a reference, so it is not possible to set a reference target
- AutosarDataError::InvalidReference: The target element is not a valid reference target for this reference
- AutosarDataError::ElementNotIdentifiable: The target element is not identifiable, so it cannot be referenced by an Autosar path
sourcepub fn get_reference_target(&self) -> Result<Element, AutosarDataError>
pub fn get_reference_target(&self) -> Result<Element, AutosarDataError>
Get the referenced element
This function will get the reference string from the character data of the element as well as the destination type from the DEST attribute. Then a lookup of the Autosar path is performed, and if an element is found at that path, then the type of the element is compared to the expected type.
The element is returned if it exists and its type is correct.
Example
let cluster_element = elements.create_named_sub_element(ElementName::CanCluster, "Cluster")?;
ref_element.set_reference_target(&cluster_element)?;
let ref_target = ref_element.get_reference_target()?;
assert_eq!(cluster_element, ref_target);Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::NotReferenceElement: The current element is not a reference, so it is not possible to get the reference target
- AutosarDataError::InvalidReference: The reference is invalid; there is no element with the referenced Autosar path
sourcepub fn set_character_data(
&self,
chardata: CharacterData
) -> Result<(), AutosarDataError>
pub fn set_character_data(
&self,
chardata: CharacterData
) -> Result<(), AutosarDataError>
set the character data of this element
This method only applies to elements which contain character data, i.e. element.content_type == CharacterData
Example
element.set_character_data(CharacterData::String("value".to_string()))?;Possible Errors
- AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
- AutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.
- AutosarDataError::IncorrectContentType: Cannot set character data on an element whoch does not contain character data
sourcepub fn insert_character_content_item(
&self,
chardata: &str,
position: usize
) -> Result<(), AutosarDataError>
pub fn insert_character_content_item(
&self,
chardata: &str,
position: usize
) -> Result<(), AutosarDataError>
Insert a character data item into the content of this element
This method only applies to elements which contain mixed data, i.e. element.content_type() == Mixed. Use create_sub_element_at to add an element instead of a character data item
Example
// mixed content elements are primarily used for documentation and description
let desc = element.create_sub_element(ElementName::Desc)?;
let l2 = desc.create_sub_element(ElementName::L2)?;
l2.insert_character_content_item("descriptive text", 0)?;Possible Errors
- AutosarDataError::IncorrectContentType the element content_type is not Mixed
- AutosarDataError::InvalidPosition the position is not valid
sourcepub fn remove_character_content_item(
&self,
position: usize
) -> Result<(), AutosarDataError>
pub fn remove_character_content_item(
&self,
position: usize
) -> Result<(), AutosarDataError>
Remove a character data item from the content of this element
This method only applies to elements which contain mixed data, i.e. element.content_type == Mixed
Example
element.insert_character_content_item("descriptive text", 0)?;
element.remove_character_content_item(0)?;Possible Errors
- AutosarDataError::IncorrectContentType the element content_type is not Mixed
- AutosarDataError::InvalidPosition the position is not valid
sourcepub fn character_data(&self) -> Option<CharacterData>
pub fn character_data(&self) -> Option<CharacterData>
Get the character content of the element
This method only applies to elements which contain character data, i.e. element.content_type() == CharacterData
Example
match element.character_data() {
Some(CharacterData::String(stringval)) => {},
Some(CharacterData::Enum(enumval)) => {},
Some(CharacterData::UnsignedInteger(intval)) => {},
Some(CharacterData::Double(dblval)) => {},
None => {},
}sourcepub fn content(&self) -> ElementContentIterator
pub fn content(&self) -> ElementContentIterator
Create an iterator over all of the content of this element
The iterator can return both sub elements and character data, wrapped as ElementContent::Element and ElementContent::CharacterData
This method is intended to be used with elements that contain mixed content.
Example
for content_item in element.content() {
match content_item {
ElementContent::CharacterData(data) => {},
ElementContent::Element(element) => {},
}
}sourcepub fn downgrade(&self) -> WeakElement
pub fn downgrade(&self) -> WeakElement
Create a weak reference to this element
A weak reference can be stored without preventing the element from being deallocated. The weak reference has to be upgraded in order to be used, which can fail if the element no longer exists.
See the documentation for Arc
Example
let weak_element = element.downgrade();sourcepub fn sub_elements(&self) -> ElementsIterator
pub fn sub_elements(&self) -> ElementsIterator
Create an iterator over all sub elements of this element
Example
for sub_element in element.sub_elements() {
// ...
}sourcepub fn get_sub_element(&self, name: ElementName) -> Option<Element>
pub fn get_sub_element(&self, name: ElementName) -> Option<Element>
Get the sub element with the given element name
Returns None if no such element exists. if there are multiple sub elements with the requested name, then only the first is returned
Example
let element = pkg.get_sub_element(ElementName::ShortName).unwrap();
assert_eq!(element.element_name(), ElementName::ShortName);sourcepub fn elements_dfs(&self) -> ElementsDfsIterator
pub fn elements_dfs(&self) -> ElementsDfsIterator
Create a depth first iterator over this element and all of its sub elements
Each step in the iteration returns the depth and an element. Due to the nature of a depth first search, the returned depth can remain the same, increase by one, or decrease by an arbitrary number in each step.
The dfs iterator will always return this element as the first item.
Example
for (depth, elem) in element.elements_dfs() {
// ...
}sourcepub fn attributes(&self) -> AttributeIterator
pub fn attributes(&self) -> AttributeIterator
Create an iterator over all the attributes in this element
Example
for attribute in element.attributes() {
println!("{} = {}", attribute.attrname, attribute.content);
}sourcepub fn attribute_value(&self, attrname: AttributeName) -> Option<CharacterData>
pub fn attribute_value(&self, attrname: AttributeName) -> Option<CharacterData>
Get the value of an attribute by name
Example
let value = file.root_element().attribute_value(AttributeName::xsiSchemalocation);sourcepub fn attribute_string(&self, attrname: AttributeName) -> Option<String>
pub fn attribute_string(&self, attrname: AttributeName) -> Option<String>
Get the content of an attribute as a string
Example
let value = element.attribute_string(AttributeName::Dest);sourcepub fn set_attribute(&self, attrname: AttributeName, value: CharacterData) -> bool
pub fn set_attribute(&self, attrname: AttributeName, value: CharacterData) -> bool
Set the value of a named attribute
If no attribute by that name exists, and the attribute is a valid attribute of the element, then the attribute will be created.
Returns true if the attribute was set.
let result = element.set_attribute(AttributeName::Dest, CharacterData::UnsignedInteger(42));
assert_eq!(result, false);sourcepub fn set_attribute_string(
&self,
attrname: AttributeName,
stringvalue: &str
) -> bool
pub fn set_attribute_string(
&self,
attrname: AttributeName,
stringvalue: &str
) -> bool
Set the value of a named attribute from a string
The function tries to convert the string to the correct data type for the attribute
Returns true if the attribute was set.
let result = element.set_attribute_string(AttributeName::T, "2022-01-31T13:59:59Z");
assert_eq!(result, true);sourcepub fn remove_attribute(&self, attrname: AttributeName) -> bool
pub fn remove_attribute(&self, attrname: AttributeName) -> bool
Remove an attribute from the element
Returns true if the attribute existed and could be removed.
Example
let result = file.root_element().remove_attribute(AttributeName::xsiSchemalocation);
// xsiSchemalocation exists in the AUTOSAR element, but it is mandatory and cannot be removed
assert_eq!(result, false);sourcepub fn serialize(&self) -> String
pub fn serialize(&self) -> String
Serialize the element and all of its content to a string
The serialized text generated for elements below the root element cannot be loaded, but it may be useful for display.
Example
let text = element.serialize();sourcepub fn list_valid_sub_elements(&self) -> Vec<(ElementName, bool, bool)>
pub fn list_valid_sub_elements(&self) -> Vec<(ElementName, bool, bool)>
List all sub_elements that are valid in the current element
The target use case is direct interaction with a user, e.g. through a selection dialog
Return Value
A list of tuples consisting of ElementName of the potential sub element bool: is the sub element named bool: can this sub element be inserted considering the current content of the element
Example
for (element_name, is_named, is_allowed) in element.list_valid_sub_elements() {
// ...
}Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl !UnwindSafe for Element
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more