There are lots of KNIME posts and examples of how to read and manipulate XML files, but I would like to build an XML file from scratch, using data contained within a flat file. Would someone be so kind to point me in the direction of how to get started.
This depends and what exactly you want to do. Can you give a short example?
I am looking to build an ODM file from data contained within a in-house data base. I just would like to know how I can bukid a schema that can then be filled with data.
My question is really how can I build up a very small XML, the bare bones e.g.
<?xml version="1.0" encoding="UTF-8"?>
Description="Sample ItemData Extension"
And then fill it with data:
GlobalVariables is a REQUIRED section in ODM markup
<StudyName>CDISC Connect-A-Thon Test Study III</StudyName>
<StudyDescription>This file contains test data from a previous CDISC Connect-A-Thon.</StudyDescription>
Internal ODM markup required metadata
<MetaDataVersion OID="v1.1.0" Name="Version 1.1.0">
<StudyEventRef StudyEventOID="SE.VISIT1" OrderNumber="1" Mandatory="Yes" />
<StudyEventDef OID="SE.VISIT1" Name="Study Event Definition" Repeating="Yes" Type="Common">
<FormRef FormOID="FORM.AE" OrderNumber="1" Mandatory="No" />
<FormDef OID="FORM.AE" Name="Form Definition" Repeating="Yes">
<ItemGroupRef ItemGroupOID="IG.AE" Mandatory="No" />
Columns defined in the table
<ItemGroupDef OID="IG.AE" Repeating="Yes"
Comment="Some adverse events from this trial">
<ItemRef ItemOID="ID.TAREA" OrderNumber="1" Mandatory="No" />
<ItemRef ItemOID="ID.PNO" OrderNumber="2" Mandatory="No" />
Column attributes as defined in the table
<ItemDef OID="ID.TAREA" SASFieldName="TAREA" Name="Therapeutic Area" DataType="text" Length="4">
<CodeListRef CodeListOID="CL.$TAREAF" />
<ItemDef OID="ID.PNO" SASFieldName="PNO" Name="Protocol Number" DataType="text" Length="15" />
I hope you can point me in the right direction
My first question is how can I either build or import the schema below:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:mdsol="http://www.mdsol.com/ns/odm/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" AsOfDateTime="2014-08-26T14:01:41" CreationDateTime="2014-08-26T14:01:41" Description="OUTPUT" FileOID="xxx_STUDY_BUILD" FileType="Snapshot" ODMVersion="1.3" SourceSystem="xxx" SourceSystemVersion="2.01.01" xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 ODM1-3-0.xsd">
+ <Study OID="1313_0020">
My second question is how do I insert data into this XML at a specific location?
There's a KNIME extension called "KNIME XML-Processing". This extension comes with a String to XML node which can be used to "compose" a XML file.
I created a simple workflow for you, showing how to create a XML column/file from your code snippet.
Thanks for your help. I have attached my workflow: My current output is this:
<ODM AsOfDateTime="2014-08-26T14:01:41" CreationDateTime="2014-08-26T14:01:44"/>
What I really want is this:
<ODM AsOfDateTime="2014-08-26T14:01:41" CreationDateTime="2014-08-26T14:01:44"><GlobalVariables>
I really want to know how I can build seperate elements and fit them together without generating New elements when combining two XML cells. I will be building the XML from files, so the string to XML will not really help me as I need the XML to be dynamically built.
I would appreciate any advice.
I guess we do not have any XML experts in the KNIME community, which is a shame.
Still waiting for help with my problem, any advice would be most welcome.
What about adding an XSLT node that transforms the current structure into the desired one?
You problem is very specific and it would be quite hard to do it even without KNIME. The only way I know of injecting XML fragments into existing documents is programmatically via the DOM API. There is no standard XML technique (such as XPath, XSLT, ...) I know of that achieves this. Therefore it's also hard to come up with node that is general enough to be useful for a wider group of users.
Your workflow is close to what you wanted, all that was missing was the naming of your root element and it's attributes. If you drop the column to XML node from your header branch, you can use those string values as attributes in the XML Element Properties tab of the XML Column Combiner configuration dialog.
Thanks for your workflow that is exactly what I wanted (I owe you a pint at the next UGM). I just have one more question:
I need to add a "Data Bound Attribute" in the last "XML Column Combiner" node. The name equals "xsi:schemaLocation". For some reason the node does not like the colon in the name. Is this a bug or by design? Like I said in my previous posts I am trying to reverse engineer an XML and they have this name.
Enhancement Request: It would be nice to have an "XML Column Resorter" node as I would like to have my Study Description above the Study Name, but the XML Column Combiner sorts automatically the columns alphanumerically. I know this will not make a difference to the final XML as all the data is there, but I would like my XML to be 1:1 identical with the one I am trying to replicate for QC purposes.