I have to create this node following this model https://gitlab.com/crossref/schema/-/blob/master/examples/journal_article_4.4.2.xml:
<jats:abstract>The abstract
</jats:abstract>
I already set the namespaces:
MY_NAMESPACES={'xsi': 'http://www.w3.org/2001/XMLSchema-instance', None: 'http://www.crossref.org/schema/4.4.2', 'jats': 'http://www.ncbi.nlm.nih.gov/JATS1', 'fr': 'http://www.crossref.org/fundref.xsd'}
attr_xsi = etree.QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation")
root = etree.Element('doi_batch', {attr_xsi: "http://www.crossref.org/schema/4.4.2 https://www.crossref.org/schemas/crossref4.4.2.xsd"}, nsmap=MY_NAMESPACES, version="4.4.2")
But I don't know how to call the jats namespace from that. Following this example Create XML files which have tags with prefix (python and lxml) I created this:
jats = "http://jats.nlm.nih.gov" #https://jats.nlm.nih.gov/archiving/tag-library/1.3d1/chapter/app-notes-namespace.html
jats_namespace = {"jats": jats}
abstract = etree.SubElement(article, "{" + jats + "}" + "abstract").text = "the abstract"
But what I get is
<ns0:abstract xmlns:ns0="http://jats.nlm.nih.gov">the abstract</ns0:abstract>
I know this is wrong, but how can I call the jats namespace set before?
Related
I am trying to create a one-to-one mapping using Pony ORM.
class ApplierIngress(ApplierObjectMapper.db.Entity):
correlation_id = orm.PrimaryKey(str)
ticket_number = orm.Required(str)
username = orm.Required(str)
status = orm.Required(str)
request_date = orm.Required(datetime)
class ApplierResult(ApplierObjectMapper.db.Entity):
correlation_id = orm.Required(ApplierIngress)
result = orm.Required(orm.LongStr)
request_date = orm.Required(datetime)
It throws error while generating the mapping
pony.orm.core.ERDiagramError: Reverse attribute for ApplierResult.correlation_id not found
I want correlation_id in ApplierResult table be the foreign key referencing to correlation_id in ApplierIngress table
Please let me know what am I doing wrong?
As error said you need to specify reverse attribute. Entities is not just Tables.
class ApplierIngress(ApplierObjectMapper.db.Entity):
correlation_id = orm.PrimaryKey(str)
ticket_number = orm.Required(str)
username = orm.Required(str)
status = orm.Required(str)
request_date = orm.Required(datetime)
result_id = orm.Optional('ApplierResult') # this attribute should be added
class ApplierResult(ApplierObjectMapper.db.Entity):
correlation_id = orm.Required(ApplierIngress)
result = orm.Required(orm.LongStr)
request_date = orm.Required(datetime)
Since this class is not yet declared you should use it as string or lambda
result_id = orm.Optional('ApplierResult')
result_id = orm.Optional(lambda: ApplierResult)
See here
Given the following code Gist
I'm trying to use attributes from my parent class , but i can't access then.
src = BluTools.sourceFile.GetValue()
dest = BluTools.destFile.GetValue()
codigo_empresa = BluTools.codigo_empresa.GetValue()
codigo_deposito = BluTools.codigo_deposito.GetValue()
data = BluTools.data_inicio.GetValue()
But give-me error :
AttributeError: 'BluTools' object has no attribute 'sourceFile'
You need to read up on how classes work in Python. You do not normally access attributes by calling the class directly. You need to either create an instance of the class:
blue = BluTools()
blue.some_attr()
Or in your case, use self instead of BluTools
src = self.sourceFile.GetValue()
dest = self.destFile.GetValue()
codigo_empresa = self.codigo_empresa.GetValue()
codigo_deposito = self.codigo_deposito.GetValue()
data = self.data_inicio.GetValue()
-Is there any way to pass Global Properties from external file or something?
-I don't want to navigate Preference-Global Properties and changing the values.
-Is there any alternative way to do this.
Thanks,
Arivazhagan
You can parse external file in groovy script Step, for example *.csv file with values into the local groovy variables, and then set value in Properties of Test Suite or Test Case or Global Properties too.
Example of parsing *.csv file:
def testDataSet = []
def index = testRunner.testCase.getPropertyValue("index")
int indx = index.toInteger()
def fileName = "phoneNumbers.csv"
//read from file
new File(fileName).eachLine { line -> testDataSet.add( line.split(";") ) }
log.info( "Read " + testDataSet.size() + " test values from " + fileName )
//convert value to properties
def testDataLine = testDataSet[indx]
phoneNumber = testDataLine[0].value as String
log.info phoneNumber
Example of set property:
testRunner.testCase.setPropertyValue("phoneNumber", phoneNumber)
indx++
String indexString = Integer.toString(indx)
testRunner.testCase.setPropertyValue("index", indexString)
Example of set Global Preporty:
globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "MyProp" )
more info provide here https://www.soapui.org/scripting-properties/tips-tricks.html
Global properties are stored in soapui-settings.xml in the user.dir. If you change it, it will be recognized by readyApi/soapUI.
I have series of xml files placed in 2 separate folders as below. My objective is to read each file one at a time from both folders and apply xmlunit comaprison methods.
Folder1 : actual1.xml
actual2.xml
actual3.xml
Folder2 : compare1.xml
compare2.xml
compare3.xml
Part1: Am reading each file at a time from both folders by using below script. I welcome suggestions if there are more simpler methods to do this
log.info "**********Read files from Folder1************"
def xml_file1 = []
new File("D:\\GroovyTest\\Folder1").eachFile{ f ->
f (f.isFile()&& f.name.contains('.xml'))
{
def filename = f.name[0..-1]
xml_file1.add(filename)
log.info filename
}
}
if (xml_file1.size() <1)
{
testRunner.fail("No request files found")
}
log.info "**********Read files from Folder2************"
def xml_file2 = []
new File("D:\\GroovyTest\\Folder2").eachFile{ f ->
if (f.isFile()&& f.name.contains('.xml'))
{
def filename = f.name[0..-1]
xml_file2.add(filename)
log.info filename
}
}
if (xml_file2.size() <1)
{
testRunner.fail("No request files found")
}
Part2: Script to perform comparison for each combination of xml files contained in array xml_file1 and xml_file2.
Am actually stuck at this part as the below script works for single files if each xml file is kept in a string, but i have to pass an array as arguments since i have series of xml files to be compared. I get a run time error - groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.FileInputStream(java.util.ArrayList) error at line: 60
InputStream xml_stream1 = new FileInputStream(xml_file1)
String xml1 = getStringFromInputStream(xml_stream1)
InputStream xml_stream2 = new FileInputStream(xml_file2)
String xml2 = getStringFromInputStream(xml_stream2)
def factory = TransformerFactory.newInstance()
def transformer = factory.newTransformer(new StreamSource(new StringReader(xslt)))
StreamResult result_xml1 = new StreamResult(new StringWriter());
transformer.transform(new StreamSource(new StringReader(xml1)), result_xml1)
xml1 = result_xml1.getWriter().toString()
StreamResult result_xml2 = new StreamResult(newStringWriter());
transformer.transform(new StreamSource(new StringReader(xml2)), result_xml2)
xml2 = result_xml2.getWriter().toString()
XMLUnit.setIgnoreComments(true)
DifferenceListener differenceListener = newIgnoreTextAndAttributeValuesDifferenceListener();
DetailedDiff myDiff = new DetailedDiff(new Diff(xml1, xml2));
myDiff.overrideDifferenceListener(differenceListener);
myDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
log.info "similar ? " + myDiff.similar()
log.info "identical ? " + myDiff.identical()
List allDifferences = myDiff.getAllDifferences();
for (Object object : allDifferences) {
Difference difference = (Difference)object;
log.info(difference);
}
Could someone also help me with methods to ignore empty tags during comparison?
Thanks
I have an 'Execute Groovy script' build step in Jenkins. This step consists of two files - a client file called createWorkspaces.groovy and a bean file called WorkspaceBean.groovy. Both live in the same location in the job workspace.
Previously running Jenkins 1.554 this ran without issues, but after upgrading to 1.594 I am getting the following error:
/jenkins/workspace/testjob/scripts/groovy/createWorkspaces.groovy: 75: unable to resolve class WorkspaceBean
# line 75, column 21.
def workspace = new WorkspaceBean()
^
1 error
I have approved the scripts in the new script approval function and I have also added the location of the files to the class path parameter in the job step as well as the location of the jenkins-core.jar file.
Any ideas why this has stopped working?
This appears to be a bug in the groovy plugin. Adding paths to the Class path field within the plugin configuration does not change the class path.
This does not work:
Adding a CLASSPATH variable via the 'Inject environment variables into the build process' plugin does work.
This works:
Try to load your jars dynamically. This is the final working solution I found. This sample is for copy network folder to local machine.
def file = new File("jcifs-1.3.18.jar")
this.class.classLoader.rootLoader.addURL(file.toURI().toURL())
def auth_server = Class.forName("jcifs.smb.NtlmPasswordAuthentication").newInstance("domain", "username", "password")
def auth_local = Class.forName("jcifs.smb.NtlmPasswordAuthentication").newInstance(null, "local_user", "password")
def source_url = args[0]
def dest_url = args[1]
def auth = auth_server
//prepare source file
if(!source_url.startsWith("\\\\"))
{
source_url = "\\\\localhost\\"+ source_url.substring(0, 1) + "\$" + source_url.substring(1, source_url.length());
auth = auth_local
}
source_url = "smb:"+source_url.replace("\\","/");
def source = Class.forName("jcifs.smb.SmbFile").newInstance(source_url,auth_server)
//prepare destination file
if(!dest_url.startsWith("\\\\"))
{
dest_url = "\\\\localhost\\"+ dest_url.substring(0, 1) + "\$" +dest_url.substring(2, dest_url.length());
auth = auth_local
}
dest_url = "smb:"+dest_url.replace("\\","/");
def dest = Class.forName("jcifs.smb.SmbFile").newInstance(dest_url,auth_local)
source.copyTo(dest)