How to get attribute value from Xml using C - c

I have the XML file as given as below
-<fmiModelDescription numberOfEventIndicators="0" variableNamingConvention="structured" generationDateAndTime="2015-06-22T14:46:19Z" generationTool="Dassault Systemes FMU Export from Simulink, ver. 2.1.1 (MATLAB 8.7 (R2014b) 08-Sep-2014)" version="1.4" author="Dan Henriksson" description="S-function with FMI generated from Simulink model BouncingBalls" guid="{76da271a-0d11-469c-bc24-0343629fb38e}" modelName="BouncingBalls_sf" fmiVersion="2.0"> <CoSimulation canHandleVariableCommunicationStepSize="true" modelIdentifier="BouncingBalls_sf"/> <DefaultExperiment stepSize="0.001" stopTime="10.0" startTime="0.0"/> -<ModelVariables>
I want to fetch the attribute value for eg GUID which is given in the above XML,how can i do that using C programming

Well the only valid answer is: use a library!
The probably best one (in terms of feature completeness) is libxml. Use this if there aren't any other concerns. There's good documentation, too.
If you need something small, there are a LOT of options, all with their limitations. I recently created badxml for this purpose. There are many other options, such as ezxml which I discovered just today in a question here.
But as I said, if size is not a concern, just use libxml, because it is widely used, well tested and feature-complete.

Related

Modularity in igraph: before and after October 2021

In igraph when I cluster the karate network (kar) with, say, cluster_fast_greedy, to give karfg, using modularity(karfg) gives 0.4345215. The deprecated option of including membership
modularity(kar, membership(karfg)) gives 0.399096. Is there an explanation for this discrepancy? (It is not fastgreedy specific, other community detection methods also give a discrepancy).
library(igraph)
library(igraphdata)
data(karate)
kar <- karate
karfg<-cluster_fast_greedy(karate)
modularity(kar, membership(karfg))
0.3990796
modularity(karfg)
0.4345215
This happens because the modularity function does not use edge weights by default, while most community detection functions do. The graph you are working with has a weight edge attribute, which will be used by cluster_fast_greedy() unless you explicitly prevent that.
This is how you can use it in modularity as well:
modularity(karate, membership(karfg), weights=E(karate)$weight)
0.4345215
Note that not all of igraph's community detection functions make use of weights, and those that do may not use it in the same way. Thus, when you call modularity explicitly, and separately from the community detection function, be careful to specify weights that match with how the community detection was done.

IloNumVarArray Vs IloNumArray

I am working on a project in which the problem is solved using CPLEX. There are two classes IloNumVarArray and IloNumArray that I do not know their difference.
I really appreciate it if someone can explain this.
Thanks
Masoud
The difference is very simple but very important.
The IloNumVarArray is used to hold the CPLEX modelling variables. These are the components used to construct your mathematical model. These variables have a domain or range of possible values (usually specified with upper and lower bounds) and they do not have values until after you have solved the problem with CPLEX.
IloNumArray is an array of simple variables in your programming language e.g. C++ doubles or ints (or the equivalents in C#, Java or whatever). These are used in your code which is creating your model and can appear as constants in your CPLEX model.

flink MultipleLinearRegression fit take 3 params

I follow the example of
https://ci.apache.org/projects/flink/flink-docs-release-1.0/apis/batch/libs/ml/multiple_linear_regression.html
but in the example the fit function only need one param,but in my code , fit require three params,
mlr.fit(training, fitParameters, fitOperation);
I thought fitParameters may be a alternative for setIterations(),setStepsize()
but what is fitOperation?
The fitOperation parameter is actually an implicit parameter which is filled in automatically by the Scala compiler. It encapsulates the MLR logic.
Since your fit function has 3 parameters, I suspect that you're using FlinkML with Flink's Java API. I would highly recommend you using the Scala API, because otherwise you will have to construct the ML pipelines manually. If you still want to do it, then take a look at the FitOperations defined in the MultipleLinearRegression companion object.

How to use phloc schematron-pure with Document -schema-definition

This question concerns phloc-schematron, a library for ISO Schematron validation.
I am creating schematron-files on the fly, so I have them available as document (or as string of course)
I cannot find a constructor for SchematronResourcePure that takes a string or document as argument, nor can I find a method to create a IReadableResource from the same.
Can someone suggest how to do this?
In case this is still relevant:
Switch to ph-schematron at https://github.com/phax/ph-schematron/ and use the static SchematronResourcePure.fromString method.
But you are right - this is a case that is currently not considered - building the Schematron from scratch. I will see, what I can do!

Automatically Generate C Code From Header

I want to generate empty implementations of procedures defined in a header file. Ideally they should return NULL for pointers, 0 for integers, etc, and, in an ideal world, also print to stderr which function was called.
The motivation for this is the need to implement a wrapper that adapts a subset of a complex, existing API (the header file) to another library. Only a small number of the procedures in the API need to be delegated, but it's not clear which ones. So I hope to use an iterative approach, where I run against this auto-generated wrapper, see what is called, implement that with delegation, and repeat.
I've see Automatically generate C++ file from header? but the answers appear to be C++ specific.
So, for people that need the question spelled out in simple terms, how can I automate the generation of such an implementation given the header file? I would prefer an existing tool - my current best guess at a simple solution is using pycparser.
update Thanks guys. Both good answers. Also posted my current hack.
so, i'm going to mark the ea suggestion as the "answer" because i think it's probably the best idea in general. although i think that the cmock suggestion would work very well in tdd approach where the library development was driven by test failures, and i may end up trying that. but for now, i need a quicker + dirtier approach that works in an interactive way (the library in question is a dynamically loaded plugin for another, interactive, program, and i am trying to reverse engineer the sequence of api calls...)
so what i ended up doing was writing a python script that calls pycparse. i'll include it here in case it helps others, but it is not at all general (assumes all functions return int, for example, and has a hack to avoid func defs inside typedefs).
from pycparser import parse_file
from pycparser.c_ast import NodeVisitor
class AncestorVisitor(NodeVisitor):
def __init__(self):
self.current = None
self.ancestors = []
def visit(self, node):
if self.current:
self.ancestors.append(self.current)
self.current = node
try:
return super(AncestorVisitor, self).visit(node)
finally:
if self.ancestors:
self.ancestors.pop(-1)
class FunctionVisitor(AncestorVisitor):
def visit_FuncDecl(self, node):
if len(self.ancestors) < 3: # avoid typedefs
print node.type.type.names[0], node.type.declname, '(',
first = True
for param in node.args.params:
if first: first = False
else: print ',',
print param.type.type.names[0], param.type.declname,
print ')'
print '{fprintf(stderr, "%s\\n"); return 0;}' % node.type.declname
print '#include "myheader.h"'
print '#include <stdio.h>'
ast = parse_file('myheader.h', use_cpp=True)
FunctionVisitor().visit(ast)
UML modeling tools are capable of generating default implementation in the language of choice. Generally there is also a support for importing source code (including C headers). You can try to import your headers and generate source code from them. I personally have experience with Enterprise Architect and it supports both of these operations.
Caveat: this is an unresearched answer as I haven't had any experience with it myself.
I think you might have some luck with a mocking framework designed for unit testing. An example of such a framework is: cmock
The project page suggests it will generate code from a header. You could then take the code and tweak it.

Resources