-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
I haven't tested this in all elements but I have provided a specific test case(TOUMarking:Terms_Of_Use) below:
input.xml:
<!--
This online template may be used as a starting point for creating STIX documents. Fill in the appropriate elements and add data as necessary. When finished, extra namespace declarations and schema locations may (but do not have to be) removed.
All content (including the markings) are for sample purposes only and do not reflect actual threat intelligence or handling instructions.
The copyright statement and license reference below (in addition to this entire comment) may be removed once this file is altered. When distributed in its current form as the STIX online template, however, it should be retained to indicate it is part of the STIX open source project.
******************************************************************************************************************************
Copyright (c) 2014, The MITRE Corporation. All rights reserved.
The contents of this file are subject to the terms of the STIX License located at http://stix.mitre.org/about/termsofuse.html.
******************************************************************************************************************************
-->
<stix:STIX_Package
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:marking="http://data-marking.mitre.org/Marking-1"
xmlns:stixCommon="http://stix.mitre.org/common-1"
xmlns:stix="http://stix.mitre.org/stix-1"
xmlns:stixVocabs="http://stix.mitre.org/default_vocabularies-1"
xmlns:TOUMarking="http://data-marking.mitre.org/extensions/MarkingStructure#Terms_Of_Use-1"
xsi:schemaLocation="
http://data-marking.mitre.org/Marking-1 http://stix.mitre.org/XMLSchema/data_marking/1.1.1/data_marking.xsd
http://stix.mitre.org/common-1 http://stix.mitre.org/XMLSchema/common/1.1.1/stix_common.xsd
http://stix.mitre.org/stix-1 http://stix.mitre.org/XMLSchema/core/1.1.1/stix_core.xsd
http://stix.mitre.org/default_vocabularies-1 http://stix.mitre.org/XMLSchema/default_vocabularies/1.1.1/stix_default_vocabularies.xsd
http://data-marking.mitre.org/extensions/MarkingStructure#Terms_Of_Use-1 http://stix.mitre.org/XMLSchema/extensions/marking/terms_of_use/1.0.1/terms_of_use_marking.xsd
"
id="INSERT_PACKAGE_ID_HERE"
version="1.1.1">
<stix:STIX_Header>
<stix:Title>TITLE</stix:Title>
<stix:Package_Intent xsi:type="stixVocabs:PackageIntentVocab-1.0">Incident</stix:Package_Intent>
<stix:Description>DESCRIPTION</stix:Description>
<!-- All handling instructions are for sample purposes only. Feel free to remove, change, and add as you see fit. -->
<stix:Handling>
<marking:Marking>
<marking:Controlled_Structure>//node()</marking:Controlled_Structure>
<marking:Marking_Structure xsi:type="TOUMarking:TermsOfUseMarkingStructureType">
<TOUMarking:Terms_Of_Use></TOUMarking:Terms_Of_Use>
</marking:Marking_Structure>
</marking:Marking>
</stix:Handling>
</stix:STIX_Header>
</stix:STIX_Package>python script:
#!/usr/bin/env python
# Copyright (c) 2014, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.
'''
File: ex_01.py
Description: Round-trip example. This script takes a STIX instance document from XML to
a binding object, then to a api object and then to a dictionary. That dictionary is then
converted back into an api object, which is then used to generate an XML document.
'''
import io
from pprint import pprint
from stix.core import STIXPackage
def main():
fn = 'input.xml'
stix_package = STIXPackage.from_xml(fn)
stix_dict = stix_package.to_dict() # parse to dictionary
#pprint(stix_dict)
stix_package_two = STIXPackage.from_dict(stix_dict) # create python-stix object from dictionary
xml = stix_package_two.to_xml() # generate xml from python-stix object
print(xml)
if __name__ == '__main__':
main()resulting xml:
<stix:STIX_Package
xmlns:marking="http://data-marking.mitre.org/Marking-1"
xmlns:TOUMarking="http://data-marking.mitre.org/extensions/MarkingStructure#Terms_Of_Use-1"
xmlns:example="http://example.com"
xmlns:stixCommon="http://stix.mitre.org/common-1"
xmlns:stixVocabs="http://stix.mitre.org/default_vocabularies-1"
xmlns:stix="http://stix.mitre.org/stix-1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://data-marking.mitre.org/Marking-1 http://stix.mitre.org/XMLSchema/data_marking/1.1.1/data_marking.xsd
http://data-marking.mitre.org/extensions/MarkingStructure#Terms_Of_Use-1 http://stix.mitre.org/XMLSchema/extensions/marking/terms_of_use/1.0.1/terms_of_use_marking.xsd
http://stix.mitre.org/common-1 http://stix.mitre.org/XMLSchema/common/1.1.1/stix_common.xsd
http://stix.mitre.org/default_vocabularies-1 http://stix.mitre.org/XMLSchema/default_vocabularies/1.1.1/stix_default_vocabularies.xsd
http://stix.mitre.org/stix-1 http://stix.mitre.org/XMLSchema/core/1.1.1/stix_core.xsd" id="INSERT_PACKAGE_ID_HERE" version="1.1.1">
<stix:STIX_Header>
<stix:Title>TITLE</stix:Title>
<stix:Package_Intent xsi:type="stixVocabs:PackageIntentVocab-1.0">Incident</stix:Package_Intent>
<stix:Description>DESCRIPTION</stix:Description>
<stix:Handling>
<marking:Marking>
<marking:Controlled_Structure>//node()</marking:Controlled_Structure>
<marking:Marking_Structure xsi:type='TOUMarking:TermsOfUseMarkingStructureType'/>
</marking:Marking>
</stix:Handling>
</stix:STIX_Header>
</stix:STIX_Package>Metadata
Metadata
Assignees
Labels
No labels