spring integration xpath namespace issue - spring-integration

I am trying to use an an xpath expression, in order to read requestId field in the xml file given below. however, this expression results in no matches. When I try to enclose the field names with single quotes, it results in a compilation error. I even tried using local-name, instead of name, in the xpath expression. I need to be able to get the value of requestId field as shown.
<int-file:outbound-channel-adapter
id="file" mode="APPEND" charset="UTF-8"
directory="C:\\Users\\dvenkat1\\Desktop\\test"
auto-create-directory="true" filename-generator-expression="#xpath(payload, '/*[name()=Envelope]/*[name()=Body]/*[name()=processArchiveRequest]/*[name()=fulfillmentRequest]/*[name()=requestHeader]/*[name()=requestID]/text()')" />
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sch="http://...schema">
<soap:Header/>
<soap:Body>
<sch:processArchiveRequest>
<sch:fulfillmentRequest>
<sch:requestHeader>
<sch:requestID>Samplereq</sch:requestID>
............
Another option would be, is to use something like this:
<int-file:outbound-channel-adapter
id="file" mode="APPEND" charset="UTF-8"
directory="C:\\Users\\dvenkat1\\Desktop\\test"
auto-create-directory="true" filename-generator-expression="#xpath(payload, 'reference exp1 here']) " />
<int-xml:xpath-expression id = "exp1"
expression="name(/soapNs:Envelope/soapNs:Body/schNs:processArchiveRequest/schNs: fulfillmentRequest/schNs:requestDetail/*[1])"
namespace-map="archiveNamespaceMap" />
<util:map id="archiveNamespaceMap">
<entry key="soapNs" value="http://www.w3.org/2003/05/soap-envelope" />
<entry key="schNs" value="http://blah../schema" />
</util:map>

It works for me like this:
filename-generator-expression="#xpath(payload, '//*[local-name()="requestID"]')"
Pay attention to the escaped " symbol.
Regarding <int-xml:xpath-expression>.
You can use it from the the filename-generator-expression as well, but you should follow with the XPathExpression and therefore use XmlPayloadConverter manually. And do that everything somewhere from the custom bean.

Related

find xml-nodes by tag with wildcard

I am trying to find any nodes in a xml whos tags start with a certain pattern.
<data>
<general>
<va value="400" /> <!--looking for this "v-tag"-->
<vb value="42" /> <!-- and this one-->
<y value="43" />
</general>
<special>
<va value="100" />
</special>
</data>
I cannot put together the xpath expression. Something like this
xyz = lxml.etree.parse( ... )
vees = xyz.xpath("general/[tag='v*']")
I would like to have vees beeing
vees
Out[64]: [<Element va at 0x....>, <Element vb at 0x...>]
Try changing:
vees = xyz.xpath("general/[tag='v*']")
to
doc.xpath('//general//*[starts-with(name(),"v")]')
and see if it works.

with vimgrep - or other vim possibility - how can i get groups of data out of a file?

I'm trying to do a vimgrep on a file in order to get only two attributs with their values out of the xml file.
so far i can get the complete lines and i'd like with the help of groups to have a better display.
:vimgrep key= % | copen
^ I'd like to add to this command the grouping possibility with "( )" ....but without success for the moment.
i'd appreciate your help in order to have a result as explained in the "result expected"
part of the file that I'm working with :
<policy name="Menu_Controls" class="User" displayName="$(string.Menu_Controls)" explainText="$(string.IE_ExplainMenu_Controls)" presentation="$(presentation.Menu_Controls)" key="Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\AllowedControls">
<parentCategory ref="AdminApproved" />
<supportedOn ref="SUPPORTED_IE5" />
<elements>
<boolean id="MCSiMenu" valueName="{275E2FE0-7486-11D0-89D6-00A0C90C9B67}">
<trueValue>
<decimal value="0" />
</trueValue>
<falseValue>
<decimal value="1" />
</falseValue>
</boolean>
<boolean id="PopupMenu_Object" valueName="{7823A620-9DD9-11CF-A662-00AA00C066D2}">
<trueValue>
<decimal value="0" />
</trueValue>
<falseValue>
<decimal value="1" />
</falseValue>
</boolean>
<boolean id="Ikonic_Control" valueName="{F5131C24-E56D-11CF-B78A-444553540000}">
<trueValue>
<decimal value="0" />
</trueValue>
<falseValue>
<decimal value="1" />
</falseValue>
</boolean>
</elements>
</policy>
<policy name="Microsoft_Agent" class="User" displayName="$(string.Microsoft_Agent)" explainText="$(string.IE_Explain_Microsoft_Agent)" presentation="$(presentation.Microsoft_Agent)" key="Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\AllowedControls">
<parentCategory ref="AdminApproved" />
<supportedOn ref="SUPPORTED_IE5" />
<elements>
<boolean id="Microsoft_Agent_Control" valueName="{D45FD31B-5C6E-11D1-9EC1-00C04FD7081F}">
<trueValue>
<decimal value="0" />
</trueValue>
<falseValue>
<decimal value="1" />
</falseValue>
</boolean>
</elements>
</policy>
my expected result :
name="Menu_Controls" key="Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\AllowedControls"
name="Microsoft_Agent" key="Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\AllowedControls"
thanks in advance for your help.
toshi
two cmds could do it:
v/<policy /d
then
%s/.* \(name="[^"]*"\).*\(key="[^"]*"\).*/\1 \2/g
My ExtractMatches plugin provides a :YankMatches command, with which you can extract the matches and put them into a scratch buffer. As a one-liner:
:execute 'YankMatches \<\%(name\|key\)="[^"]*"' | new | put!
Result:
name="Menu_Controls"
key="Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\AllowedControls"
name="Microsoft_Agent"
key="Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings\AllowedControls"
If you find :vimgrep and the quickfix list really helpful, you can use the editqf.vim plugin to make the quickfix list of your grep results editable, and then use e.g. a variation of the :%s command given in #Kent's answer to strip off the extraneous stuff.

Build a string in MSBuild as a concatenation of a base string n-times

I have a numer, "n" in a property in MSBuild. I also have a string "Str" that needs to be duplicated n-times to achieve a final string that is the repetition of "Str" n times.
Eg. If n is 3 and Str is "abc", what I want to obtain is "abcabcabc"
Since one cannot loop in MSBuild, I don't know how to achieve this. Perhaps with an item group, but how do I create one based on a property containing an "n" count?
Thanks!
To create a String repeated n times, you can also do this (at least in MSBuild Tools v4.0):
<SomeRepeatedString>$([System.String]::New("-", 40))</SomeRepeatedString>
usually for things like this I resolve to using inline C#, as it costs me less time than searching all over the internet to find a 'true' msbuild solution; here you go:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MyString>abc</MyString>
<Count>3</Count>
</PropertyGroup>
<UsingTask TaskName="RepeatString" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<s ParameterType="System.String" Required="true" />
<n ParameterType="System.Int32" Required="true" />
<result ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs"><![CDATA[
result = string.Concat( Enumerable.Repeat( s, n ) );
]]></Code>
</Task>
</UsingTask>
<Target Name="doit">
<RepeatString s="$(MyString)" n="$(Count)">
<Output PropertyName="result" TaskParameter="result" />
</RepeatString>
<Message Text="Result = $(result)"/>
</Target>
</Project>

access ant property value for pattern variable in file.eachFileMatch() in Groovy

I am unable to run the code for moving file, when i use the ant macrodef attribute in groovy task inside the macrodef.
<macrodef name="dirmove">
<attribute name="todir" />
<attribute name="fromdir" />
<attribute name="includes" default="*" />
<sequential>
<var name="todir" value="#{todir}" />
<var name="fromdir" value="#{fromdir}" />
<var name="includes" value="#{includes}" />
<groovy>
File dir1 = new File(properties.'fromdir');
File dir2 = new File(properties.'todir');
def pattern = properties.get('includes')
println pattern;
dir1.eachFileMatch ~/pattern/, {
f->
boolean fileMoved = f.renameTo(new File(dir2, f.getName()));
//assert f.name == '1.txt' //**because File object is immutable, so I am just checking for the existing of previous file name. It is still there.
println fileMoved;
}
</groovy>
</sequential>
</macrodef>
This code correctly prints the value of pattern, which is coming from attribute value. But the eachFileMatch function doesn't picks up the spec
dir1.eachFileMatch ~/pattern/, {
should be
dir1.eachFileMatch ~/${pattern}/, {
As pattern is a String variable, so you need to add it in to the regex pattern as such.
Previously, you were just searching for all files called pattern

CopyIntoItems Sharepoint SOAP Action Parameters

I am trying to upload a file using SOAP Action
POST /_vti_bin/Copy.asmx HTTP/1.1
Host: my.hostname.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>string</SourceUrl>
<DestinationUrls>
<string>string</string>
<string>string</string>
</DestinationUrls>
<Fields>
<FieldInformation Type="Invalid or Integer or Text or Note or DateTime or Counter or Choice or Lookup or Boolean or Number or Currency or URL or Computed or Threading or Guid or MultiChoice or GridChoice or Calculated or File or Attachments or User or Recurrence or CrossProjectLink or ModStat or AllDayEvent or Error" DisplayName="string" InternalName="string" Id="guid" Value="string" />
<FieldInformation Type="Invalid or Integer or Text or Note or DateTime or Counter or Choice or Lookup or Boolean or Number or Currency or URL or Computed or Threading or Guid or MultiChoice or GridChoice or Calculated or File or Attachments or User or Recurrence or CrossProjectLink or ModStat or AllDayEvent or Error" DisplayName="string" InternalName="string" Id="guid" Value="string" />
</Fields>
<Stream>base64Binary</Stream>
</CopyIntoItems>
</soap:Body>
</soap:Envelope>
I wish to upload a PDF file or Doc file. I am using Firefox extension Poster
I have the source and destination URLs
What should be the values of <FieldInformation> and <Stream> ?
Thanks in advance
Viv
The stream value needs to be the base64binary representation of the file. So for example I have a text file that contains the text "123". Using this site http://www.base64converter.com/ I converted the text to base64 which translated to "MTIz". So if I was trying to upload my file I would put "MTIz" (without quotes) into the Stream tag. Something like this:
<Stream>MTIz</Stream>
The FieldInformation tags need to contain any SharePoint properties that need to be associated with the document you are uploading. So if you want to set the title property to "My Document" you would need something like this:
<FieldInformation Type="Text" DisplayName="Title" InternalName="Title" Id="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Value="My Document" />

Resources