Can exams2moodle export additional metainfo such as idnumber and tags? - moodle

When I export the xml file of a multiple choice question, it contains the following lines:
<idnumber>arbitrary_id_set_by_user</idnumber>
<answernumbering>ABCD</answernumbering>
<tag></tag>
Is there a way to add idnumber, answernumbering and tag to the metainformation section of the question so that r-exams can export to moodle XML as <idnumber>idnumber</idnumber>,<answernumbering>ABCD</answernumbering>, <tag>tag1</tag>, and <tag>tag2</tag> etc?

The <answernumbering> tag can be set in exams2moodle() via the answernumbering= argument, see ?exams2moodle. The reason for this is that this is set in the same way for all exercises in a quiz. This is more consistent than setting it individually and potentially inconsistently in the meta-information of the different exercises.
The <idnumber> tag appears to be used by Moodle only for internal purposes. It is also not mentioned in the official Moodle XML documentation at https://docs.moodle.org/311/en/Moodle_XML_format. Hence we did not implement it in exams2moodle().
The <tag> is currently not supported in exams2moodle() because we felt that it would be more important to have tags in the Rmd (or Rnw) exercise itself and not the Moodle version of the exercise. For structuring the content on the Moodle side the exsection meta-information can be used, see boxhist for a worked example.
Finally, you can add arbitrary metainformation by using the exextra tag. This is used, for example, in the essayreg exercise template. However, there is no general way of using this extra metainformation to insert additional XML code in the exams2moodle() output. To do that, the source code underlying exams2moodle() would have to be adapted correspondingly.

Related

manipulating Microsoft Word DOCX files that have links and track changes using Python

I have been using the excellent python-docx package to read, modify, and write Microsoft Word files. The package supports extracting the text from each paragraph. It also allows accessing a paragraph a "run" at a time, where the run is a set of characters that have the same font information. Unfortunately, when you access a paragraph by runs, you lose the links, because the package does not support links. The package also does not support accessing change tracking information.
My problem is that I need to access change tracking information. Or, more specifically, I need to copy paragraphs that have change tracking indicated from one document to another.
I've tried doing this at the XML level. For example, this code snippet appends the contents of file1.docx to file2.docx:
from docx import Document
doc1 = Document("file1.docx")
doc2 = Document("file2.docx")
doc2.element.body.append(doc1.element.body)
doc2.save("file2-appended.docx")
When I try to open the file on my Mac for complicated files, I get this error:
But if I click OK, the contents are there. The manipulation also works without problem for very simple files.
What am I missing?
The .element attribute is really an "internal" interface and should be named ._element. In most other places I have named it that. What you're getting there is the root element of the document part. You can see what it is by calling:
print(doc2.element.xml)
That element has one and only one w:body element below it, which is what you get when with doc2.element.body (.xml will work on that too, btw, if you want to inspect that element).
What your code is doing is appending one body element at the end of another w:body element and thereby forming invalid XML. The WordprocessingML vocabulary is quite strict about what element can follow another and how many and so forth. The only surprise for me is that it actually sometimes works for you, I take it :)
If you want to manipulate the XML directly, which is what the ._element attribute is there for, you need to do it carefully, in view of the (complex) WordprocessingML XML Schema.
Unlike when you stick to the published API, there's no safety net once ._element (or .element) appears in your code.
Inside the body XML can be relationships to external document parts, like images and hyperlinks. These will only be valid within the document in which they appear. This might explain why some files can be repaired.

Columns Layout export

Sparx Enterprise Architect offers the possibility to define custom layouts for list views in the package browser and to save these definitions. When exporting a Project file (*.eap) via xmi, these definitions are not included in the export-file and thus lost. I wonder whether there exists a way to transfer columns layout definitions between two EA-Projects.
Many thanks in advance for every hint!
As Geert suggested the layout is stored in the registry.
[HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\OPTIONS]
holds a key PKG_BRWSE_LAYOUTS with the comma separated list of profile names (so you better don't use comma in your profile name ;-).
The detailed information is stored in
[HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\EA1200Workspace\BCGPGrids\EA_ELEMENT_LIST_<name>BCGPGrid-0]
where <name> is the according profile name.
For a sample layout here they looked like
"Columns"=hex:11,00,01,00,00,00,01,00,00,00,01,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00
"ColumnWidth"=hex:11,00,16,00,00,00,04,01,00,00,50,00,00,00,50,00,00,00,50,00,\
00,00,50,00,00,00,50,00,00,00,50,00,00,00,50,00,00,00,50,00,00,00,50,00,00,\
00,50,00,00,00,50,00,00,00,50,00,00,00,50,00,00,00,50,00,00,00,50,00,00,00
"ColumnOrder"=hex:08,00,00,00,00,00,01,00,00,00,06,00,00,00,02,00,00,00,0d,00,\
00,00,0e,00,00,00,0f,00,00,00,10,00,00,00
"Groupping"=hex:00,00
"LastFieldChooserPos"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
"IsFieldChooserVisible"=dword:00000000
"IsFieldChooserThemed"=dword:00000001
"SortColumns"=hex:00,00
I have to leave that to you to decipher the coding used here. But for a pure ex-/import you probably don't need to do that.

How can we get value from DOM Properties in JMeter?

I'm trying to record a scenario of SAP CRM.
But I have a problem due to that everytime I login SAP CRM generates a new hashed token and will be used in URL like below:
See Image 1 Here
I tried to check where is the information stored, and in firebug and I found it in DOM tab:
See Image 2 Here
Is there any way to get the value from this DOM Properties using Jmeter?
Usually the choices are in:
CSS/JQuery Extractor
XPath Extractor
Regular Expression Extractor
Choose the one, you're most familiar with. Usually it is Regular Expression Extractor, however parsing HTML with regular expressions is not a good idea, moreover you will be very sensitive to DOM changes (part of the element goes to next line, attributes change positions, etc.).
So I would recommend choosing between CSS and XPath, but choose them wisely. I.e. if the number of styles on the page is not too big - go for CSS, if there are a lot of styles but the DOM itself is not very complicated - choose XPath.

How to read form fragment references in a pdf document?

I am working with adobe LiveCycle ES4 and I am attempting to make a custom LiveCycle component (in java) that counts references to a specified form fragment. However I am having some difficulty finding documentation on form fragments in pdf files. So my question is how would I go about reading form fragment references from a pdf document?
Also any documentation, API, or library that may help me with this task would be greatly appreciated.
--Form Fragments--
A form fragment is a collection of form objects (fields, buttons, shapes, tables, etc) as well as related style/formatting that is saved as a separate .xsd file in a form fragment library (usually a directory on the livecycle server that holds the .xsd files). References to form fragments can be inserted into a form when working in LiveCycle Designer.This is particularly useful for creating many similar forms (such as a form fragment with fields for contact information). When a form fragment is edited the changes are reflected across all forms that hold a reference to that fragment (when the pdf is opened and has access to the form fragment library.
The PDF specification currently is an official ISO standard - ISO 32000. You should be able to get the document from the ISO organisation or from your country's standards organisation.
However, before being an ISO standard, PDF was developed and maintained by Adobe and they still have the specification available on their site: http://www.adobe.com/devnet/pdf/pdf_reference.html
There are differences between this specification and the ISO 32000 specification document, but they are largely from an editorial manner so for your purpose I'd look at the Adobe document.
Using the additional information in the comments, your test file and a low level PDF document browser (pdfToolbox in this case - attention, I'm affiliated with this product), I found following information:
In the "Catalog" object for your test PDF, you'll find a key named "AcroForm" that points to a dictionary with information about your form.
In that "AcroForm" dictionary you'll find a key called "XFA" that contains what appears to be almost all information about the XFA form that LifeCycle designer generated.
That "XFA" key points to an array which seems to consist of pairs of information. Element 0 is a string called "preamble", element 1 seems to be the data belonging to that string. So each pair of elements is a bit of information.
The information in that array consists of "preamble", "config", "template", "localeset", "xmpmeta" and "postamble". If you look at the element for "template" (the 6th element in the array if you calculate 1-based), you'll find the data you are looking for. The data is stored as a FlateDecoded stream that you'll have to uncompress - then it's just XML data that should be fairly easy to parse. In it are three lines that for you should be of particular interest:
<subform x="6.35mm" y="6.35mm" name="TestFragment1"
<subform x="3.175mm" y="34.925mm" name="TestFragment2"
<subform x="0.125in" y="2.75in" name="TestFragment2"
I'm assuming the XFA specification pointed to by mkl contains more information about these things, but it seems like simply looking for "subform" elements in the XML should get you the references to the form fragments pretty easily.
In the XFA xml data in the sample PDF you provided there are processing instructions like this:
<?templateDesigner expand 1?><?designerFragmentSource CjxzdWJmb3JtIHVzZWhyZWY9Ii4uXC4uXC4uXEFkb2JlXEFkb2JlIExpdmVDeWNsZSBFUzRcZm9y
bV9mcmFnbWVudHNcVGVzdEZyYWdtZW50MS54ZHAjc29tKCR0ZW1wbGF0ZS5mb3JtMS5UZXN0RnJh
Z21lbnQxKSIgeD0iNi4zNW1tIiB5PSI2LjM1bW0iIHhtbG5zPSJodHRwOi8vd3d3LnhmYS5vcmcv
c2NoZW1hL3hmYS10ZW1wbGF0ZS8zLjMvIgo+PD90ZW1wbGF0ZURlc2lnbmVyIGV4cGFuZCAxPz48
L3N1YmZvcm0KPg==?>
Decoding the base64 encoded argument in there one gets:
<subform usehref="..\..\..\Adobe\Adobe LiveCycle ES4\form_fragments\TestFragment1.xdp#som($template.form1.TestFragment1)" x="6.35mm" y="6.35mm" xmlns="http://www.xfa.org/schema/xfa-template/3.3/"
><?templateDesigner expand 1?></subform
>
So it looks like your
custom LiveCycle component (in java) that counts references to a specified form fragment
should parse the XFA XML, look for these designerFragmentSource processing instructions, and analyze them.
Please be aware, though, that these processing instructions most likely are proprietary Adobe stuff (I at least did not find them in the current XFA specification). Thus, as soon some third party tool touches the XFA XML, the PIs might not be accurate anymore. You actually even cannot be sure what happens in different Adobe software versions.

Customizing single entry templates in ExpressionEngine (1.6.x)

This is either very annoying or very embarrassing. I've set up most of my blog, but I can't figure out where or how the heck I set up single entry templates as opposed to the section/weblog containing them. I just can't find information on how to do it for the life of me.
This is especially important, because I want to define the canonical link for all entries, since ExpressionEngine links to entries in all kinds of ways.
So, the case is that I have a Blog section/weblog with an index working as the front page for mydomain.com. This lists all my entries as you would imagine a regular blog to do. The problem arises when I need to customize the code for the single entries' links.
If you have a template set up already which is showing a multitude of entries and you want a single entry page for each entry then what you need to do is this :
{exp:channel:entries
channel="default_site"
sort="asc"
disable="member_data|pagination|categories"}
{title}
{/exp:channel:entries}
Then in the template shown above by template_group/template_name (please change those to whatever your template group and template names actually are ;-) ) you will place this code :
{exp:channel:entries
channel="default_site"
limit="1"
dynamic="yes"
sort="asc"
disable="member_data|pagination|categories"}
{title}
{/exp:channel:entries}
This will then show you just the one entry as you will have used the {url_title_path="template_group/template_name"} in the first channel entries tag above which would basically create a URI something like this :
http://www.example.com/template_group/template_name/url_title_of_my_posted_entry
On the second (template_group/template_name) single entry template page it will see the URL title and use this to filter down the channel entries tag to just that one entry.
Hope that helps a bit.
Best wishes,