Yang model for remainder operation (%) - ietf-netmod-yang

I want to create yang model with for some integer range e.g from 1000 to maximum and values must be entered in steps of 500. Is there any way I can make use of remainder(modulus) % operator in yang or range function like python with steps.
Or I just need to use pattern with some regex.

Use a must constraint to further constrain an integer type value that is already constrained with a range.
module modulus {
yang-version 1.1;
namespace "org:so:modulus";
prefix "som";
leaf value {
type int32 {
range "1000..max";
}
must ". mod 500 = 0" {
error-message "values must be entered in steps of 500";
}
}
}
XPath specification provides the mod operator.
<?xml version="1.0" encoding="utf-8"?>
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<som:value xmlns:som="org:so:modulus">1501</som:value>
</data>
Results in:
Error at (3:3): failed assert at "/nc:data/som:value": values must be entered in steps of 500
While
<?xml version="1.0" encoding="utf-8"?>
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<som:value xmlns:som="org:so:modulus">2000</som:value>
</data>
is okay.

Related

How to use a dynamic string variable in an XPath expression in matlab

I'm trying to find the children of a specific node (concept) of an XMl document in matlab using Xpath.
I used the following code I get 5 children which is true.
expression = xpath.compile('//concept\[#name="con1"\]/\*');
Childs = expression.evaluate(xDoc, XPathConstants.NODESET);
But for my project I have to use the string values of the attributes "name" of each concept in dynamic manner, so I stored them in vector in order to cal them one by one.
For example, ConceptName(1)="con1", however, when I execute the following code, I get zero children:
expression = xpath.compile('//concept\[#name="ConceptName(1)"\]/\*');
Childs = expression.evaluate(xDoc, XPathConstants.NODESET);
If there is someone who can help me to call the sting variables to the path expression I would be very grateful.
Thank you in advance.
Here is how my XML doc look like, My desired outpout whould be a list of four concepts (the first children of the concept which has the name="con1"), but I must extract the name of the parent concept dynamicly because the structure whould be unkowen.
<?xml version="1.0" encoding="UTF-8"?>
<taxonomy>
<concept name="con1">
<concept name="con11">
<concept name="con1033990258">
<concept name="con271874239">
<concept name="con1657241849">
<concept name="con1448945150">
<instance name="inst686829093"/>
<instance name="inst1379512917"/>
<instance name="inst2072196703"/>
</concept>
</concept>
</concept>
</concept>
<concept name="con12"> </concept>
<concept name="con13"></concept>
<concept name="con14"></concept>
</concept>
</taxonomy>
This is my code
% get the xpath mechanism into the workspace
import javax.xml.xpath.*
factory = XPathFactory.newInstance;
xpath = factory.newXPath;
% read the XML file
filedir = 'C:\Users\Asus\Documents\Asma\MatlabCode\Contribution2\WSC2009_XML'; %location of the file
files = dir(fullfile(filedir, '*.xml'));
xDoc = xmlread(fullfile(filedir, files(1).name)); % read the XML doc but return "[#document: null]". The xmlread function returns a Java object that represents the file's Document Object Model, or DOM. The "null" is simply what the org.apache.xerces.dom.DeferredDocumentImpl's implementation of toString() dumps to the MATLAB Command Window
XDocInMatlab = xmlwrite(xDoc); % show the XML file
taxonomy = xDoc.getElementsByTagName('taxonomy'); %% get the root elment
concepts = xDoc.getElementsByTagName('concept'); %% get the concept elemnt node
concept_Matrix = strings(concepts.getLength,1);
for i = 0 : concepts.getLength-1
conceptName = string(concepts.item(i).getAttribute('name'));
concept_Matrix(i+1,1) = conceptName;
if concepts.item(i).hasChildNodes
expression = xpath.compile('//concept[#name=conceptName]/*');
Childs = expression.evaluate(xDoc, XPathConstants.NODESET);
% Iterate through the nodes that are returned.
for j = 0:Childs.getLength-1
ChildsName(j+1) = char(Childs.item(j).getAttribute('name'));
end
end
end
The expression #name="ConceptName(1)" doesn't select anything because you don't have any elements whose name attribute has the value "ConceptName(1)".
It's hard to know how to correct your code because you don't really tell us what you thought it might mean. You say you stored the attribute names "in a vector" but there's no such thing as a vector in XPath, so I really don't know what you did or what you are trying to achieve.
My guess is that you want to replace the following line
expression = xpath.compile('//concept\[#name="ConceptName(1)"\]/\*')
with something like this:
expression = xpath.compile('//concept\[#name="' + ConceptName(1) + '"\]/\*')
Note that this works only if ConceptName is a string array type (with double quotes), not a char vector (single quotes).
Note also that it is not necessary to escape square brackets and asterisks in strings:
expression = xpath.compile('//concept[#name="' + ConceptName(1) + '"]/*')

How to receive xml nodes inside a time range by using xquery

I have an xml with something like that inside
<SFEvents>
<EventList>
<Event>
<ID>1111</ID>
<Type>Measurement</Type>
<TimeStamp>2015-09-28T09:50:27.514</TimeStamp>
<Space>Main_area</Space>
<SourceID>Thermometer_3</SourceID>
<Content>
<Measurement>
<!-- From B2MML standard (OpSegmentDataType) -->
<ID/>
<Description>Temperature of a power resistance</Description>
<Value>
<ValueString>100</ValueString>
<UnitOfMeasure>oC</UnitOfMeasure>
</Value>
</Measurement>
</Content>
</Event>
<Event>..</Event>
...
</EventList>
with many events and I currently try to receive with xquery all the Event nodes that have their Timestamp inside a time range
I use this code
all_xmls_String=session.execute("xquery for $b in doc('CIDEMdb/CIDEM.xml')
let $date_string as xs:string :=$b/SFEvents/EventList/Event/TimeStamp/data()
let $date as xs:dateTime := xs:dateTime($date_string)
where $date ge xs:dateTime('"+startdate+"') and $date le
xs:dateTime('"+enddate+"') return $b/SFEvents/EventList");
but I receive this error
Cannot cast xs:untypedAtomic+ to xs:string: ("2015-09-28T09:50:27.514", ...).
Any idea?
The problem is that you are iterating over the EventList document, which has a cardinality of 1, while selecting $b/SFEvents/EventList/Event/TimeStamp/data(), a sequence of TimeStamp values, and assigning it to a variable that expects a single value. Your query also returns an EventList, but you say you want to return Events.
There are several ways to do this, but the easiest way given your existing query it to simply iterate over the Event elements instead, select the single TimeStamp value, and then return the selected Events.
for $b in doc('CIDEMdb/CIDEM.xml')//SFEvents/EventList/Event
let $date_string as xs:string :=$b/TimeStamp/data()
let $date as xs:dateTime := xs:dateTime($date_string)
where $date ge xs:dateTime('"+startdate+"') and $date le xs:dateTime('"+enddate+"')
return $b

Iterate all XML nodes and their childs

What would be the most efficient way in VBScript to iterate through an XML file.
I am looking for a way to iterate all nodes in the XML file. I cannot use XQL queries, because I really do need to iterate all nodes to check all attributes in the file.
PS: Basically I am writing a script to replace references to file paths. The problem is that these file paths can be in a big number of places. (But that's for me to find out). I only need help with the XML iterating part.
While I suspect that putting some intelligence and XPath expressions into the search would increase effiency, this
Option Explicit
Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument" )
oXDoc.async = False
oXDoc.load "..\data\31677574.xml"
If 0 = oXDoc.ParseError Then
WScript.Echo oXDoc.documentElement.xml
walk oXDoc.documentElement, 0
Else
WScript.Echo oXDoc.ParseError.Reason
End If
Sub walk(e, i)
WScript.Echo Space(i), e.tagName
Dim a
For Each a In e.Attributes
WScript.Echo Space(i + 1), a.name, a.value
Next
Dim c
For Each c In e.childNodes
walk c, i + 2
Next
End Sub
output:
cscript 31694559.vbs
<Configuration>
<Add SourcePath="\\sample" ApplicationEdition="32">
<Product ID="SampleProductID">
<Language ID="en-us"/>
<Language ID="en-us"/>
</Product>
</Add>
</Configuration>
Configuration
Add
SourcePath \\sample
ApplicationEdition 32
Product
ID SampleProductID
Language
ID en-us
Language
ID en-us
will visit all elements and their attributes.

I need to concatenate several strings

I am new to stuctured text and I would like to know how to concatenate several string. The cleanest way possible. I this instance I only need to change one variable when creating the string. I have another where I need to do 2. That number will probably grow. The purpose of this is so I can send XML message to an HTTP server. This is for logging data.
In this instance it is the reader variable which is a word.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/receiveHeartbeat</Action>
</s:Header>
<s:Body>
<receiveHeartbeat xmlns="http://tempuri.org/">
<reader>**Word Variable**</reader>
</receiveHeartbeat>
</s:Body>
</s:Envelope>
You can chain CONCAT functions like so:
concat3: STRING := CONCAT(CONCAT(str1, str2), str3);
However, beware that by default STRING is only 80 characters (bytes) long. You can specify the size using parenthesis:
concat3: STRING(255) := CONCAT(CONCAT(str1, str2), str3);
But again, the standard CONCAT function only accepts and returns strings of up to 255 in length!
If you need strings longer than 255, then check Working with Strings More Than 255 Characters in the codesys documentation
If you are using Wago then you should have access to their CONCAT functions...CONCAT3(),CONCAT4()...CONCAT9(). This is much cleaner than nesting a lot of the standard CONCAT funct
I take it that you need to do this in JavaScript.
var replaceDue = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\
<s:Header>\
<Action s:mustUnderstand=\"1\"xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/IService/receiveHeartbeat</Action>\
</s:Header>\
<s:Body>\
<receiveHeartbeat xmlns=\"http://tempuri.org/\">\
<reader>**Word Variable**</reader>\
</receiveHeartbeat>\
</s:Body>\
</s:Envelope>";
var wordVariable = "value to replace";
var replaceDone = replaceDue.replace("**Word Variable**", wordVariable);
I think I have found a solution. I don't like it though. It's not very clean.
Reader_ID: STRING := '0';
msg: STRING(500);
Msg1: STRING(250) := '<s:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><s:Header>';
Msg2: STRING(250) := '<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/receiveHeartbeat</Action>';
Msg3: STRING := '</s:Header><s:Body><receiveHeartbeat xmlns="http://tempuri.org/"><reader>';
MsgAfter: STRING := '</reader></receiveHeartbeat></s:Body></s:Envelope>';
msg := CONCAT(Msg1,Msg2);
msg := CONCAT(msg,Msg3);
msg := CONCAT(msg,Reader_ID);
msg := CONCAT(msg,MsgAfter);
It seems that string sizes are limited to 500 characters. Since the point of this is to create an XML message to send via HTTP. What happens when my messages inevitably get larger than 500 character. I am using the WagoLibHttp_02 library for http.

How to specify comma , space unicode value in app.config(C#3.0)

In the app.config file if I use
<add key = "FileDelimeter" value ="&#2c;"/> as unicode for COMMA, it is throwing error
Invalid character in a decimal number 'c'
For SPACE, <add key = "FileDelimeter" value =""/> the error is
Character'', hex value 0*14 is illegal
in xml
while <add key = "FileDelimeter" value =" "/> for "\t" worked.
Where is the mistake?
Kindly give a generic solution.
Thanks
The &# prefix denotes a decimal (base 10) number. Try using &#x (the 'x' is for Hexadecimal) as the prefix:
<add key = "FileDelimeter" value =","/>