Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ColinTalbert/605e901d63e324d518aeb333f5315f28 to your computer and use it in GitHub Desktop.
Save ColinTalbert/605e901d63e324d518aeb333f5315f28 to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example showing how to control the position of where nodes are inserted."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pymdwizard.core.xml_utils import XMLRecord, XMLNode"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<citeinfo>\n",
" <origin>Scott Ikard</origin>\n",
" <origin>Andrew Teeple</origin>\n",
" <origin>Jason Payne</origin>\n",
" <origin>Greg Stanton</origin>\n",
" <origin>Ryan Banta</origin>\n",
" <pubdate>2017</pubdate>\n",
" <title>14.86 km Profiles of the Electric and Self-potential Fields Measured in the Lower Guadalupe River Channel, Texas Interior Gulf Coastal Plain, September 2016</title>\n",
" <geoform>Tabular digital, spreadsheet and comma-delimited CSV file.</geoform>\n",
" <pubinfo>\n",
" <pubplace>Denver, Colorado</pubplace>\n",
" <publish>U.S. Geological Survey</publish>\n",
" </pubinfo>\n",
" <onlink>https://doi.org/10.5066/F7CJ8CDH</onlink>\n",
" <lworkcit>\n",
" <citeinfo>\n",
" <origin>Scott Ikard</origin>\n",
" <origin>Andrew Teeple</origin>\n",
" <origin>Jason Payne</origin>\n",
" <origin>Greg Stanton</origin>\n",
" <origin>Ryan Banta</origin>\n",
" <pubdate>2017</pubdate>\n",
" <title>New Insights on Scale-dependent Surface and Groundwater Exchange from a Floating Self-potential Dipole</title>\n",
" <geoform>Journal Article</geoform>\n",
" <pubinfo>\n",
" <pubplace>Denver, Colorado</pubplace>\n",
" <publish>Journal of Environmental and Engineering Geophysics</publish>\n",
" </pubinfo>\n",
" </citeinfo>\n",
" </lworkcit>\n",
"</citeinfo>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fname = r\"C:\\Users\\talbertc\\Downloads\\New_Insights_SWGW_Exchange_Metadata.xml\"\n",
"md = XMLRecord(fname)\n",
"md.metadata.idinfo.citation.citeinfo"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Note that the list needs to be reversed to preserve it's ordering\n",
"#### alternately you could create an index variable that you increment"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"authors = ['one', 'two', 'three']\n",
"authors.reverse()\n",
"\n",
"for author in authors:\n",
" author_node = XMLNode(tag='origin', text=author)\n",
" md.metadata.idinfo.citation.citeinfo.add_child(author_node, index=5)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<citeinfo>\n",
" <origin>Scott Ikard</origin>\n",
" <origin>Andrew Teeple</origin>\n",
" <origin>Jason Payne</origin>\n",
" <origin>Greg Stanton</origin>\n",
" <origin>Ryan Banta</origin>\n",
" <origin>one</origin>\n",
" <origin>two</origin>\n",
" <origin>three</origin>\n",
" <pubdate>2017</pubdate>\n",
" <title>14.86 km Profiles of the Electric and Self-potential Fields Measured in the Lower Guadalupe River Channel, Texas Interior Gulf Coastal Plain, September 2016</title>\n",
" <geoform>Tabular digital, spreadsheet and comma-delimited CSV file.</geoform>\n",
" <pubinfo>\n",
" <pubplace>Denver, Colorado</pubplace>\n",
" <publish>U.S. Geological Survey</publish>\n",
" </pubinfo>\n",
" <onlink>https://doi.org/10.5066/F7CJ8CDH</onlink>\n",
" <lworkcit>\n",
" <citeinfo>\n",
" <origin>Scott Ikard</origin>\n",
" <origin>Andrew Teeple</origin>\n",
" <origin>Jason Payne</origin>\n",
" <origin>Greg Stanton</origin>\n",
" <origin>Ryan Banta</origin>\n",
" <pubdate>2017</pubdate>\n",
" <title>New Insights on Scale-dependent Surface and Groundwater Exchange from a Floating Self-potential Dipole</title>\n",
" <geoform>Journal Article</geoform>\n",
" <pubinfo>\n",
" <pubplace>Denver, Colorado</pubplace>\n",
" <publish>Journal of Environmental and Engineering Geophysics</publish>\n",
" </pubinfo>\n",
" </citeinfo>\n",
" </lworkcit>\n",
"</citeinfo>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md.metadata.idinfo.citation.citeinfo"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment