Not equal xPath query limitations - xpath

I need to find logs from EventViewer in Forwarded Events based on computer name, excluding the ones which aren't interesting for me.
My query is like that
*[(System[(Computer!='comp1')]) and
(System[(Computer!='comp2')]) and
(System[(Computer!='comp3')]) and
(System[(Computer!='comp4')]) and
(System[(Computer!='comp5')]) and
(System[(Computer!='comp6')]) and
(System[(Computer!='comp7')]) and
(System[(Computer!='comp8')]) and
(System[(Computer!='comp9')]) and
(System[(Computer!='comp10')]) and
(System[(Computer!='comp11')]) and
(System[(Computer!='comp12')]) and
(System[(Computer!='comp13')]) and
(System[(Computer!='comp14')]) and
(System[(Computer!='comp15')])]
This query works fine unless I add one more condition
and [(Computer!='comp16')])
After that filter stops working and all logs are displayed.
Notice that if I put comp16 instead of comp15 or instead of comp12 everything works fine. So problem is not in the new condition.
The situation is opposite if I use equality filter
(System[(Computer='comp1')]) or
(System[(Computer='comp2')]) or
...
(System[(Computer='comp15')]) or
(System[(Computer='comp16')]) and so on
Filter works fine with much larger queries.
So why not equal operator does not work in large queries?
EDIT
Filter by EventRecordID has the same problem
EDIT 2
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-A5BA-3E3B0328C30D}" />
<EventID>4624</EventID>
<Version>1</Version>
<Level>0</Level>
<Task>12544</Task>
<Opcode>0</Opcode>
<TimeCreated SystemTime="2017-08-18T17:06:15.595105400Z" />
<EventRecordID>1</EventRecordID>
<Correlation />
<Execution ProcessID="584" ThreadID="7100" />
<Channel>Security</Channel>
<Computer>comp1</Computer>
<Security />
</System>
<EventData>
<Data Name="TargetUserName">userName</Data>
<Data Name="TargetDomainName">DOMAIN</Data>
...
<Data Name="ProcessName">-</Data>
<Data Name="IpAddress">-</Data>
<Data Name="IpPort">-</Data>
</EventData>
</Event>

You haven't shown your XML, but it's hard to envisage an XML structure on which this query makes any sense.
Consider the simpler
*[(System[(Computer!='comp1')]) and
(System[(Computer!='comp2')])]
If there is only one System with only one Computer, then this returns true if the Computer is neither 'comp1' nor 'comp2'. But if there is more than one System, or more than one Computer, and if the Computers are not all the same value, then there will inevitably be at least one Computer that is not 'comp1', and at least one that is not 'comp2', and the predicate will therefore always be true.
Usually when people write A!=B in XPath, they should have written not(A=B).

Related

BizTalk Mapping Fields to a Sequence

I am getting my hands on BizTalk and VS. My input schema looks something similar to this.
<root>
<order>
<orderid>
<orderdate>
...
...
and the output schema
<order>
<header:sequence>
<element name="orderid">
<element name="orderdate">
...
...
</header:sequence>
In short, in output, the header is a sequence of complex types and individual nodes in the source are enumerated as the sequence in the output.
How do we solve this in Visual Studio?
What you need to do is having a looping functoid that goes from each of the element being mapped and to the repeating destination element. And then two links from the source elements the first that is a standard link Copy text value, the second that goes to the name attribute, for which you change the link to Copy name.
Input
<root>
<order>
<orderid>1234567890</orderid>
<orderdate>2020-01-28</orderdate>
</order>
</root>
Output
<order>
<header>
<element name="orderid">1234567890</element>
<element name="orderdate">2020-01-28</element>
</header>
</order>
Note: You can change the order of what is output by using the reorder inputs in the Configure Looping Functoid.

Block annoying numbers on freeswitch

I use freeswitch and I would like to block some annoying numbers. So far I tried modify inbound_call.xml like this
<extension name="annoying1">
<condition field="destination_number" expression="^5022xxxx$">
<action application="log" data="NOTICE To jest Rozmowa przych (testowo muzyczka).: ${destination_number}"/>
<action application="answer"/>
<action application="playback" data="/home/mwalko/przywitanie.wav"/>
<action application="hangup"/>
</condition>
</extension>
It doesn't work, should I change this "destination_number"? How can I recognize if for example 5022xxxx calls?
Seems like this "destination_number" points the number which someone called, not the calling one.
destination_number contains the digits entered by the caller, so try out caller_id_number. But keep in mind, that this can be faked.
condition uses regular expressions for matching, so you need to use a dot (.) instead of "x". You can also use something like ^5022\d{4}$

xpath - find datetimes textnodes

I have some XML with elements that contain values with mixed data types. For example:
<someroot>
<event>
<dt>21.10.15 08:00</dt>
</event>
<event>
<dt>10:00</dt>
</event>
<event>
<dt>21/10/15 08:00</dt>
</event>
</someroot>
How can I find all the text nodes that contain only datetime values? Note that dt elements can be at different depths and may just contain times.
Xpath doesn't provide ways to find text nodes by mask/regex
But it has usefull functions like starts-with(),ends-with()

XSLT Sort parent node based on specific attribute of a child

first post ever, have done lots of searching but cannot find an answer specific enough or more importantly, relevant enough. Note that I am a business analyst, not a developer, so I may be missing some understanding here.
We produce XML that we then process to produce a report. Where data can be represented by a table, the XML contains details for the table title (ELEMENT_HEADING), table header row (PROMPTS), then repeating nodes representing the rows (DATA) and columns (VALUES).
The problem I am facing is I need to sort the DATA node based on a text value of the node where the node has a specific attribute value.
In the sample XML provided below, I need to sort the DATA node based on the VALUE text value for the attribute #pic='TRORGPCNT' in ascending order i.e the DATA node with TRORGPCNT of 10 should appear before the DATA node with 90. Then when the report is produced the table rows are in ascending percentage order.
I hope have explained myself clearly enough :)
Any tips on how I might accomplish this?
Sample XML:
<PROPOSAL_ELEMENT multi="Y" pec="TEACHRESP" elem_mandatory="N" elem_visible="Y">
<ELEMENT_HEADING pec="TEACHRESP">Teaching Responsibility</ELEMENT_HEADING>
<PROMPTS>
<PROMPT pic="TRORGUN" item_mandatory="Y" item_visible="Y">Faculty or School with teaching responsibility</PROMPT>
<PROMPT pic="TRORGPCNT" item_mandatory="Y" item_visible="Y">Teaching responsibility %</PROMPT>
</PROMPTS>
<DATA elem_mandatory="N" elem_visible="Y" delete_ind="N">
<VALUES>
<VALUE pic="TRORGUN" item_mandatory="Y" item_visible="Y" item_description="FACULTY OF NURSING AND HEALTH" display_in_summary_tab="Y" summary_order="">FACULTY OF NURSING AND HEALTH</VALUE>
<VALUE pic="TRORGPCNT" item_mandatory="Y" item_visible="Y" item_description="" display_in_summary_tab="Y" summary_order="">90</VALUE>
</VALUES>
</DATA>
<DATA elem_mandatory="N" elem_visible="Y" delete_ind="N">
<VALUES>
<VALUE pic="TRORGUN" item_mandatory="Y" item_visible="Y" item_description="FACULTY OF ARTS" display_in_summary_tab="Y" summary_order="">FACULTY OF ARTS</VALUE>
<VALUE pic="TRORGPCNT" item_mandatory="Y" item_visible="Y" item_description="" display_in_summary_tab="Y" summary_order="">10</VALUE>
</VALUES>
</DATA>
Sorting in XSLT is accomplished using the xsl:sort instruction, which must appear as the first child of the for-each or apply-templates that selects the nodes you want to sort. If you're selecting the set of DATA element nodes then an appropriate sorting instruction would be
<xsl:sort select="VALUES/VALUE[#pic='TRORGPCNT']"
data-type="number" />

Web.Config Transform xml comments

How can I either select a comment or insert a comment using Web.config transforms?
Nowhere can I find any information on this.
I am trying to do either:
1) Insert a piece of xml (<serviceAuthorization impersonateCallerForAllOperations="true"/>) before an existing comment in the Web.config
OR
2) Insert a comment and xml at the end of a set of siblings:
As far as I can tell the Web.config transforms do not support xPath axes, I have tried a number of them to try and insert a node before the first comment:
<serviceAuthorization impersonateCallerForAllOperations="true" xdt:Transform="InsertBefore(/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior[#name='behaviorOne']/serviceMetadata/preceding::comment()[1])"/>
<serviceAuthorization impersonateCallerForAllOperations="true" xdt:Transform="InsertBefore(/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior[#name='behaviorOne']/child::node()[1]"/>
I have tried a few others, but you get the idea. I just get an error when previewing the transform.
I also can't seem to find any information on how to insert a comment. Am I missing something?
I believe that transformations are limited to operating on elements or attributes. At least, none of the documentation on xdt:Transform mentions anything that could be used to add a comment.
As for the Locator, there does seem to be some support for axes as I was able to use the following:
<spring >
<objects xmlns="http://www.springframework.net">
<object >
<constructor-arg index="0" type="System.Uri" value="https://example.com/test" xdt:Locator="Condition(../#name='requestConfig' and #index='0')" xdt:Transform="SetAttributes(value)"/>
</object>
</objects>
when operating on the following:
<spring >
<objects xmlns="http://www.springframework.net">
<object name="requestConfig" type="Example.Namespace.RequestConfig, Example" singleton ="true">
<constructor-arg index="0" type="System.Uri" value="https://example.com/production"/>
<constructor-arg index="1" value="45000"/>
</object>
</objects>
As you can see, the above uses the parent axis in order to match the element to be transformed.
Bit late to the party but for those googling I found a bit of a workaround - if you insert a node it inserts any comments inside the node, obviously you need to remove it first. Ie:
<customErrors xdt:Transform="Remove" />
<customErrors mode="On" defaultRedirect="Hub/Error" xdt:Transform="Insert">
<!-- comment -->
</customErrors>
The downside is that it destroys the child nodes but I try and put the comment as low as possible to alleviate the damage.

Resources