Can I insert my data-context in the text suggestions bar? - windows-phone-7

Suggestions bar: http://i.msdn.microsoft.com/dynimg/IC530993.png
I'd like to know if there's a way to put my data in this bar programmatically.

I think you can't add words to the Predictive Text bar in the Windows Phone.
What you can do is use the autocomplete feature:
http://developer.nokia.com/Community/Wiki/How_to_use_Auto_Complete_Box_in_Windows_Phone
And don't forget to add the scope of the keyboard
<TextBox>
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Text" />
</InputScope>
</TextBox.InputScope>
</TextBox>
There are multiple Input Scopes
<TextBox Name="myTextBox" InputScope="Text"/>
There are ways to enumerate this as this post points out
var inputScopes = new List<string>();
FieldInfo[] array = typeof(InputScopeNameValue).GetFields(
BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo fi in array)
{
inputScopes.Add(fi.Name);
}
this.DataContext = inputScopes;
AddressCity
AddressCountryName
AddressCountryShortName
AddressStateOrProvince
AddressStreet
AlphanumericFullWidth
AlphanumericHalfWidth
ApplicationEnd
Bopomofo
Chat
CurrencyAmount
CurrencyAmountAndSymbol
CurrencyChinese
Date
DateDay
DateDayName
DateMonth
DateMonthName
DateYear
Default
Digits
EmailNameOrAddress
EmailSmtpAddress
EmailUserName
EnumString
FileName
FullFilePath
Hanja
Hiragana
KatakanaFullWidth
KatakanaHalfWidth
LogOnName
Maps
NameOrPhoneNumber
Number
NumberFullWidth
OneChar
Password
PersonalFullName
PersonalGivenName
PersonalMiddleName
PersonalNamePrefix
PersonalNameSuffix
PersonalSurname
PhraseList
PostalAddress
PostalCode
Private
RegularExpression
Search
Srgs
TelephoneAreaCode
TelephoneCountryCode
TelephoneLocalNumber
TelephoneNumber
Text
Time
TimeHour
TimeMinorSec
Url
Xml
Yomi

Related

How to change the text highlight color?

The weight of the day yesterday, I tried to add this code so that it changes the highlight color of the text to the one shown in the picture. I found a lot of information on the Internet, but unfortunately, it does not work in the context of my code.
What to do?) How to change the color of the text selection?
Option Explicit
Dim WA,WD,Sel ' Объявляем переменные
'Создаем объект¬–приложение Microsoft Word
Set WA=WScript.CreateObject("Word.Application")
' Можно было использовать конструкцию
' Set WA=CreateObject("Word.Application")
Set WD=WA.Documents.Add 'Создаем новый документ (объект Document)
WA.Visible=true ' Делаем Word видимым
Set Sel=WA.Selection 'Создаем объект Selection
Sel.Font.Size=14 'Устанавливаем размер шрифта
Sel.ParagraphFormat.Alignment=1 'Выравнивание по центру
Sel.Font.Bold=true 'Устанавливаем полужирный шрифт
Sel.TypeText "Понятие сценариев" & vbCrLf 'Печатаем строку текста
Sel.Font.Bold=false 'Отменяем полужирный шрифт
Sel.ParagraphFormat.Alignment=0 'Выравнивание по левому краю
'Печатаем строку текста
Sel.TypeText " Сценарий – это пакетный файл, позволяющий автоматизировать действия системного администратора."
The end result (picture)
You can use the HighlightColorIndex property with one of the WdColorIndex constants:
WdColorIndex enumeration (Word)
With the code you provided, you would use Sel.Range.HighlightColorIndex = 10 I think, but you can experiment.
You can also use Sel.Range.Shading.BackgroundPatternColor with the same constants or an RGB value directly.

IGrouping does not contain a definition for Sum

Would anyone have an idea what's up here? I'm loading an XML file, parsing it and using LINQ to get some summary info. Here's the XML document:
<?xml version="1.0" encoding="utf-8"?>
<root>
<Ticker>
<Name>MSFT</Name>
<PurchaseDate>
2009-01-01
</PurchaseDate>
<Shares>44</Shares>
</Ticker>
<Ticker>
<Name>MSFT</Name>
<PurchaseDate>
2009-03-01
</PurchaseDate>
<Shares>33</Shares>
</Ticker>
<Ticker>
<Name>GOOG</Name>
<PurchaseDate>
2009-03-01
</PurchaseDate>
<Shares>122</Shares>
</Ticker>
<Ticker>
<Name>AAPL</Name>
<PurchaseDate>
2019-03-01
</PurchaseDate>
<Shares>89</Shares>
</Ticker>
</root>
My code:
var xmlStr = File.ReadAllText("ClientInfo.xml");
var Summary = XElement.Parse(xmlStr);
var data = from acct in Summary.Elements("Ticker")
select new
{
Ticker = (string)acct.Element("Name"),
Shares = (int)acct.Element("Shares")
};
var groupedDataByTicker = from acct in data
group acct by acct.Ticker into g
select new
{
Ticker = g.Key,
Shares = g.Sum(),
};
Works fine but when I add the g.Sum() bit I get this message:
'IGrouping>' does not contain a definition for 'Sum' and the best extension method overload 'Queryable.Sum(IQueryable)' requires a receiver of type 'IQueryable'
I can't make sense of it, what am I doing wrong?
In your code, you are trying to find the sum of the group itself.
Instead, you should be summing by the Shares property:
var groupedDataByTicker = from acct in data
group acct by acct.Ticker into g
select new
{
Ticker = g.Key,
Shares = g.Sum(row => row.Shares),
};

Retrieve the value of a XML attribute in VBS

<Requirement Description="description" Operation="Configure">
<Action ID="1000" Name="Split">
<Contract>
<Parameter Name="Version">4</Parameter>
<Parameter Name="DefaultServer">192.168.00.</Parameter>
<Parameter Name="DefaultUser">administrator</Parameter>
<Parameter Name="DefaultPassword">password</Parameter>
<Parameter Name="DefaultDomain">192.168.00.00</Parameter>
<Parameter Name="Split">1</Parameter>
</Contract>
</Action>
</Requirement>
From the above XML document my aim is to replace the IP address for both the attributes default server and default domain from a VBScript.
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load(XMLFullPath)
Set NodeList = objXMLDoc.documentElement.SelectNodes("//Parameter")
NodeList(i).nodeName
Give name as Parameter and NodeList(i).Text gives me values like 4, IP address, administrator and others. But I am not able to get the attribute name so that I can directly change the value of the attribute.
To answer your question, you can use the getAttribute function to access an attribute's value:
NodeList(i).getAttribute("Name")
You can also add a predicate to the XPath expression in your SelectNodes call to retrieve only the desired elements:
Set NodeList = objXMLDoc.documentElement.SelectNodes("//Parameter[#Name = 'DefaultServer' or #Name = 'DefaultDomain']")
This way, you don't have to retrieve and loop through the Parameter nodes that you're not interested in.
A bit rusty, but I think you can use this to retrieve the nodevalue by nodename:
Function getTag(nList, nName)
Dim i
i = 0
Do while i < nList.childNodes.length
if (nList.childNodes(i).nodeName = nName) then
getTag = nList.childNodes(i).childNodes(0).text
Exit Function
end if
i = i + 1
Loop
End Function
And to set it, probably
Sub setTag(nList, nName, val)
Dim i
i = 0
Do while i < nList.childNodes.length
if (nList.childNodes(i).nodeName = nName) then
nList.childNodes(i).childNodes(0).text = val
Exit Sub
end if
i = i + 1
Loop
End Sub

How to get the list of filter names in CIFilter class?

I am using the following code for exposure adjustment and its working. I need the filter names for sharpen, denoise, highlighs, color temperature, shadows, blur, etc.
[CIFilter filterWithName: #"CIExposureAdjust"
keysAndValues: #"inputImage", [_imageView image], nil];
I was writing to your earlier post link to all filters. I will repeat: link to all filters.
And for example You need Blur effect. Blur is category and have 7 filters:
CIBoxBlur
CIDiscBlur
CIGaussianBlur
CIMedianFilter
CIMotionBlur
CINoiseReduction
CIZoomBlur.
And etc..
I found the list of names in CIFilter class, core image filters. here is the link names in CIFilter and the list of the filters.
Filters
CICategoryBlur
CIBoxBlur
CIDiscBlur
CIGaussianBlur
CIMaskedVariableBlur
CIMedianFilter
CIMotionBlur
CINoiseReduction
CICategoryColorAdjustment
CIColorClamp
CIColorControls
CIColorMatrix
CIColorPolynomial
CIExposureAdjust
CIGammaAdjust
CIHueAdjust
CILinearToSRGBToneCurve
CISRGBToneCurveToLinear
CITemperatureAndTint
CIToneCurve
CIVibrance
CIWhitePointAdjust
CICategoryColorEffect
CIColorCrossPolynomial
CIColorCube
CIColorCubeWithColorSpace
CIColorInvert
CIColorMap
CIColorMonochrome
CIColorPosterize
CIFalseColor
CIMaskToAlpha
CIMaximumComponent
CIMinimumComponent
CIPhotoEffectChrome
CIPhotoEffectFade
CIPhotoEffectInstant
CIPhotoEffectMono
CIPhotoEffectNoir
CIPhotoEffectProcess
CIPhotoEffectTonal
CIPhotoEffectTransfer
CISepiaTone
CIVignette
CIVignetteEffect
CICategoryCompositeOperation
CIAdditionCompositing
CIColorBlendMode
CIColorBurnBlendMode
CIColorDodgeBlendMode
CIDarkenBlendMode
CIDifferenceBlendMode
CIDivideBlendMode
CIExclusionBlendMode
CIHardLightBlendMode
CIHueBlendMode
CILightenBlendMode
CILinearBurnBlendMode
CILinearDodgeBlendMode
CILuminosityBlendMode
CIMaximumCompositing
CIMinimumCompositing
CIMultiplyBlendMode
CIMultiplyCompositing
CIOverlayBlendMode
CIPinLightBlendMode
CISaturationBlendMode
CIScreenBlendMode
CISoftLightBlendMode
CISourceAtopCompositing
CISourceInCompositing
CISourceOutCompositing
CISourceOverCompositing
CISubtractBlendMode
CICategoryDistortionEffect
CIBumpDistortion
CIBumpDistortionLinear
CICircleSplashDistortion
CICircularWrap
CIDroste
CIDisplacementDistortion
CIGlassDistortion
CIGlassLozenge
CIHoleDistortion
CILightTunnel
CIPinchDistortion
CIStretchCrop
CITorusLensDistortion
CITwirlDistortion
CIVortexDistortion
CICategoryGenerator
CIAztecCodeGenerator
CICheckerboardGenerator
CICode128BarcodeGenerator
CIConstantColorGenerator
CILenticularHaloGenerator
CIPDF417BarcodeGenerator
CIQRCodeGenerator
CIRandomGenerator
CIStarShineGenerator
CIStripesGenerator
CISunbeamsGenerator
CICategoryGeometryAdjustment
CIAffineTransform
CICrop
CILanczosScaleTransform
CIPerspectiveCorrection
CIPerspectiveTransform
CIPerspectiveTransformWithExtent
CIStraightenFilter
CICategoryGradient
CIGaussianGradient
CILinearGradient
CIRadialGradient
CISmoothLinearGradient
CICategoryHalftoneEffect
CICircularScreen
CICMYKHalftone
CIDotScreen
CIHatchedScreen
CILineScreen
CICategoryReduction
CIAreaAverage
CIAreaHistogram
CIRowAverage
CIColumnAverage
CIHistogramDisplayFilter
CIAreaMaximum
CIAreaMinimum
CIAreaMaximumAlpha
CIAreaMinimumAlpha
CICategorySharpen
CISharpenLuminance
CIUnsharpMask
CICategoryStylize
CIBlendWithAlphaMask
CIBlendWithMask
CIBloom
CIComicEffect
CIConvolution3X3
CIConvolution5X5
CIConvolution7X7
CIConvolution9Horizontal
CIConvolution9Vertical
CICrystallize
CIDepthOfField
CIEdges
CIEdgeWork
CIGloom
CIHeightFieldFromMask
CIHexagonalPixellate
CIHighlightShadowAdjust
CILineOverlay
CIPixellate
CIPointillize
CIShadedMaterial
CISpotColor
CISpotLight
CICategoryTileEffect
CIAffineClamp
CIAffineTile
CIEightfoldReflectedTile
CIFourfoldReflectedTile
CIFourfoldRotatedTile
CIFourfoldTranslatedTile
CIGlideReflectedTile
CIKaleidoscope
CIOpTile
CIParallelogramTile
CIPerspectiveTile
CISixfoldReflectedTile
CISixfoldRotatedTile
CITriangleKaleidoscope
CITriangleTile
CITwelvefoldReflectedTile
CICategoryTransition
CIAccordionFoldTransition
CIBarsSwipeTransition
CICopyMachineTransition
CIDisintegrateWithMaskTransition
CIDissolveTransition
CIFlashTransition
CIModTransition
CIPageCurlTransition
CIPageCurlWithShadowTransition
CIRippleTransition
CISwipeTransition
All you need to do is ask CIFilter for the filter names. You can then ask each filter for its attributes, which returns a dictionary that describes each input and output parameter that the filter accepts.
NSArray* filters = [CIFilter filterNamesInCategories:nil];
for (NSString* filterName in filters)
{
NSLog(#"Filter: %#", filterName);
NSLog(#"Parameters: %#", [[CIFilter filterWithName:filterName] attributes]);
}
For example, this is the output of the above code for the CIZoomBlur filter:
Filter: CIZoomBlur
Parameters: {
CIAttributeDescription = "Simulates the effect of zooming the camera while capturing the image.";
CIAttributeFilterCategories = (
CICategoryBlur,
CICategoryVideo,
CICategoryStillImage,
CICategoryBuiltIn
);
CIAttributeFilterDisplayName = "Zoom Blur";
CIAttributeFilterName = CIZoomBlur;
CIAttributeReferenceDocumentation = "http://developer.apple.com/cgi-bin/apple_ref.cgi?apple_ref=//apple_ref/doc/filter/ci/CIZoomBlur";
inputAmount = {
CIAttributeClass = NSNumber;
CIAttributeDefault = 20;
CIAttributeDescription = "The zoom-in amount. Larger values result in more zooming in.";
CIAttributeDisplayName = Amount;
CIAttributeIdentity = 0;
CIAttributeMin = 0;
CIAttributeSliderMax = 200;
CIAttributeSliderMin = 0;
CIAttributeType = CIAttributeTypeDistance;
CIUIParameterSet = CIUISetBasic;
};
inputCenter = {
CIAttributeClass = CIVector;
CIAttributeDefault = "[150 150]";
CIAttributeDescription = "The x and y position to use as the center of the effect.";
CIAttributeDisplayName = Center;
CIAttributeType = CIAttributeTypePosition;
CIUIParameterSet = CIUISetBasic;
};
inputImage = {
CIAttributeClass = CIImage;
CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
CIAttributeDisplayName = Image;
CIUIParameterSet = CIUISetBasic;
};
outputImage = {
CIAttributeClass = CIImage;
};
}
Most of the time, though, you'll probably just use the docs.
May be you can try following method of CIFilter class
+ (NSArray *)filterNamesInCategory:(NSString *)category
In Swift (4.2, at the time of writing this), you can use this code to get all filter names:
For filters in a specified category:
CIFilter.filterNames(inCategory: "Name_of_the_category")
For filters in specified categories:
CIFilter.filterNames(inCategories: ["Name_of_the_category_1", "Name_of_the_category_2"])
For filters in all categories, just pass nil either in inCategory or inCategories:
CIFilter.filterNames(inCategory: nil)
or
CIFilter.filterNames(inCategories: nil)
All the functions above returns an Array of the filter names in String values:
[
"CIAccordionFoldTransition",
"CIAdditionCompositing",
"CIAffineClamp",
"CIAffineTile",
"CIAffineTransform",
"CIAreaAverage",
"CIAreaHistogram"...
]
NSLog(#"Distortion: %#", [CIFilter filterNamesInCategory:kCICategoryDistortionEffect]);
NSLog(#"Blurs: %#", [CIFilter filterNamesInCategory:kCICategoryBlur]);
NSLog(#"Color effects: %#", [CIFilter filterNamesInCategory:kCICategoryColorEffect]);
NSLog(#"Color adjustment: %#", [CIFilter filterNamesInCategory:kCICategoryColorAdjustment]);
NSLog(#"Built-in effects: %#", [CIFilter filterNamesInCategory:kCICategoryBuiltIn]);
iOS 14, Swift 5
Must confess not easy to read, but an answer that is comparable to the first one on Objective C.
for filtername in filters {
print("filter \(filtername)")
print("attributes \(CIFilter.init(name: filtername)?.attributes.keys.description)")
}
Produces this ...
filter CIAccordionFoldTransition
attributes Optional("[\"inputImage\", \"CIAttributeFilterDisplayName\", \"inputTargetImage\", \"CIAttributeFilterAvailable_iOS\", \"CIAttributeFilterAvailable_Mac\", \"inputNumberOfFolds\", \"inputFoldShadowAmount\", \"inputBottomHeight\", \"CIAttributeReferenceDocumentation\", \"inputTime\", \"CIAttributeFilterCategories\", \"CIAttributeFilterName\"]")
filter CIAdditionCompositing
attributes Optional("[\"CIAttributeFilterCategories\", \"CIAttributeFilterName\", \"CIAttributeFilterDisplayName\", \"inputImage\", \"CIAttributeReferenceDocumentation\", \"CIAttributeFilterAvailable_iOS\", \"CIAttributeFilterAvailable_Mac\", \"inputBackgroundImage\"]")
So the info is there in these long strings, you just need to pick it out :)
Noah Gilmore has a very handy filter tool to demo and document almost all cifilters & filter parms..
See on the app store 'CIFilter.io'. He also has the same on the web site https://cifilter.io
iOS 14, Swift 5
Here you can find also array of the CIFilter functions which is supported with the protocol.
CIFilter.hueSaturationValueGradient(),
CIFilter.linearGradient(),
CIFilter.radialGradient(),
CIFilter.smoothLinearGradient(),
CIFilter.sharpenLuminance(),
CIFilter.unsharpMask(),
CIFilter.dotScreen(),
CIFilter.hatchedScreen(),
CIFilter.lineScreen(),
CIFilter.bicubicScaleTransform(),
CIFilter.edgePreserveUpsample(),
CIFilter.keystoneCorrectionCombined(),
CIFilter.keystoneCorrectionHorizontal(),
CIFilter.keystoneCorrectionVertical(),
CIFilter.lanczosScaleTransform(),
CIFilter.perspectiveCorrection(),
CIFilter.perspectiveRotate(),
CIFilter.perspectiveTransform(),
CIFilter.perspectiveTransformWithExtent(),
CIFilter.straighten(),
CIFilter.accordionFoldTransition(),
CIFilter.barsSwipeTransition(),
CIFilter.copyMachineTransition(),
CIFilter.disintegrateWithMaskTransition(),
CIFilter.dissolveTransition(),
CIFilter.flashTransition(),
CIFilter.modTransition(),
CIFilter.pageCurlTransition(),
CIFilter.pageCurlWithShadowTransition(),
CIFilter.rippleTransition(),
CIFilter.swipeTransition(),
CIFilter.additionCompositing(),
CIFilter.colorBlendMode(),
CIFilter.colorBurnBlendMode(),
CIFilter.colorDodgeBlendMode(),
CIFilter.darkenBlendMode(),
CIFilter.differenceBlendMode(),
CIFilter.divideBlendMode(),
CIFilter.exclusionBlendMode(),
CIFilter.hardLightBlendMode(),
CIFilter.hueBlendMode(),
CIFilter.lightenBlendMode(),
CIFilter.linearBurnBlendMode(),
CIFilter.linearDodgeBlendMode(),
CIFilter.luminosityBlendMode(),
CIFilter.maximumCompositing(),
CIFilter.minimumCompositing(),
CIFilter.multiplyBlendMode(),
CIFilter.multiplyCompositing(),
CIFilter.overlayBlendMode(),
CIFilter.pinLightBlendMode(),
CIFilter.saturationBlendMode(),
CIFilter.screenBlendMode(),
CIFilter.softLightBlendMode(),
CIFilter.sourceAtopCompositing(),
CIFilter.sourceInCompositing(),
CIFilter.sourceOutCompositing(),
CIFilter.sourceOverCompositing(),
CIFilter.subtractBlendMode(),
CIFilter.colorAbsoluteDifference(),
CIFilter.colorClamp(),
CIFilter.colorControls(),
CIFilter.colorMatrix(),
CIFilter.colorPolynomial(),
CIFilter.colorThreshold(),
CIFilter.colorThresholdOtsu(),
CIFilter.depthToDisparity(),
CIFilter.disparityToDepth(),
CIFilter.exposureAdjust(),
CIFilter.gammaAdjust(),
CIFilter.hueAdjust(),
CIFilter.linearToSRGBToneCurve(),
CIFilter.sRGBToneCurveToLinear(),
CIFilter.temperatureAndTint(),
CIFilter.toneCurve(),
CIFilter.vibrance(),
CIFilter.whitePointAdjust(),
CIFilter.colorCrossPolynomial(),
CIFilter.colorCube(),
CIFilter.colorCubesMixedWithMask(),
CIFilter.colorCubeWithColorSpace(),
CIFilter.colorCurves(),
CIFilter.colorInvert(),
CIFilter.colorMap(),
CIFilter.colorMonochrome(),
CIFilter.colorPosterize(),
CIFilter.dither(),
CIFilter.documentEnhancer(),
CIFilter.falseColor(),
CIFilter.labDeltaE(),
CIFilter.maskToAlpha(),
CIFilter.maximumComponent(),
CIFilter.minimumComponent(),
CIFilter.paletteCentroid(),
CIFilter.palettize(),
CIFilter.photoEffectChrome(),
CIFilter.photoEffectFade(),
CIFilter.photoEffectInstant(),
CIFilter.photoEffectMono(),
CIFilter.photoEffectNoir(),
CIFilter.photoEffectProcess(),
CIFilter.photoEffectTonal(),
CIFilter.photoEffectTransfer(),
CIFilter.sepiaTone(),
CIFilter.thermal(),
CIFilter.vignette(),
CIFilter.vignetteEffect(),
CIFilter.xRay(),
CIFilter.bumpDistortion(),
CIFilter.bumpDistortionLinear(),
CIFilter.circleSplashDistortion(),
CIFilter.circularWrap(),
CIFilter.displacementDistortion(),
CIFilter.droste(),
CIFilter.glassDistortion(),
CIFilter.glassLozenge(),
CIFilter.holeDistortion(),
CIFilter.lightTunnel(),
CIFilter.ninePartStretched(),
CIFilter.ninePartTiled(),
CIFilter.pinchDistortion(),
CIFilter.stretchCrop(),
CIFilter.torusLensDistortion(),
CIFilter.twirlDistortion(),
CIFilter.vortexDistortion(),
CIFilter.affineClamp(),
CIFilter.affineTile(),
CIFilter.eightfoldReflectedTile(),
CIFilter.fourfoldReflectedTile(),
CIFilter.fourfoldRotatedTile(),
CIFilter.fourfoldTranslatedTile(),
CIFilter.glideReflectedTile(),
CIFilter.kaleidoscope(),
CIFilter.opTile(),
CIFilter.parallelogramTile(),
CIFilter.perspectiveTile(),
CIFilter.sixfoldReflectedTile(),
CIFilter.sixfoldRotatedTile(),
CIFilter.triangleKaleidoscope(),
CIFilter.triangleTile(),
CIFilter.twelvefoldReflectedTile(),
CIFilter.attributedTextImageGenerator(),
CIFilter.aztecCodeGenerator(),
CIFilter.barcodeGenerator(),
CIFilter.checkerboardGenerator(),
CIFilter.code128BarcodeGenerator(),
CIFilter.lenticularHaloGenerator(),
CIFilter.meshGenerator(),
CIFilter.pdf417BarcodeGenerator(),
CIFilter.qrCodeGenerator(),
CIFilter.randomGenerator(),
CIFilter.roundedRectangleGenerator(),
CIFilter.starShineGenerator(),
CIFilter.stripesGenerator(),
CIFilter.sunbeamsGenerator(),
CIFilter.textImageGenerator(),
CIFilter.blendWithAlphaMask(),
CIFilter.blendWithBlueMask(),
CIFilter.blendWithMask(),
CIFilter.blendWithRedMask(),
CIFilter.bloom(),
CIFilter.comicEffect(),
CIFilter.convolution3X3(),
CIFilter.convolution5X5(),
CIFilter.convolution7X7(),
CIFilter.convolution9Horizontal(),
CIFilter.convolution9Vertical(),
CIFilter.coreMLModel(),
CIFilter.crystallize(),
CIFilter.depthOfField(),
CIFilter.edges(),
CIFilter.edgeWork(),
CIFilter.gaborGradients(),
CIFilter.gloom(),
CIFilter.heightFieldFromMask(),
CIFilter.hexagonalPixellate(),
CIFilter.highlightShadowAdjust(),
CIFilter.lineOverlay(),
CIFilter.mix(),
CIFilter.pixellate(),
CIFilter.pointillize(),
CIFilter.saliencyMap(),
CIFilter.shadedMaterial(),
CIFilter.spotColor(),
CIFilter.spotLight(),
CIFilter.bokehBlur(),
CIFilter.boxBlur(),
CIFilter.discBlur(),
CIFilter.gaussianBlur(),
CIFilter.maskedVariableBlur(),
CIFilter.median(),
CIFilter.morphologyGradient(),
CIFilter.morphologyMaximum(),
CIFilter.morphologyMinimum(),
CIFilter.morphologyRectangleMaximum(),
CIFilter.morphologyRectangleMinimum(),
CIFilter.motionBlur(),
CIFilter.noiseReduction(),
CIFilter.zoomBlur] as [AnyObject]

How to extract links, text and timestamp from webpage via Html Agility Pack

I am using Html Agility Pack and are trying to extract the links and link text from the following html code. The webpage is fetched from a remote page and the saved locally as a whole. Then from this local webpage I am trying to extract the links and link text. The webpage naturally has other html code like other links text, etc inside its page but is removed here for clarity.
<span class="Subject2"><a href="/some/today.nsf/0/EC8A39D274864X5BC125798B0029E305?open">
Description 1 text here</span> <span class="time">2012-01-20 08:35</span></a><br>
<span class="Subject2"><a href="/some/today.nsf/0/EC8A39XXXX264X5BC125798B0029E312?open">
Description 2 text here</span> <span class="time">2012-01-20 09:35</span></a><br>
But the above are the most unique content to work from when trying to extract the links and linktext.
This is what I would like to see as the result
<link>/some/today.nsf/0/EC8A39D274864X5BC125798B0029E305</link>
<title>Description 1 text here</title>
<pubDate>Wed, 20 Jan 2012 07:35:00 +0100</pubDate>
<link>/some/today.nsf/0/ EC8A39XXXX264X5BC125798B0029E312</link>
<title>Description 2 text here</title>
<pubDate> Wed, 20 Jan 2012 08:35:00 +0100</pubDate>
This is my code so far:
var linksOnPage = from lnks in document.DocumentNode.SelectNodes("//span[starts-with(#class, 'Subject2')]")
(lnks.Name == "a" &&
lnks.Attributes["href"] != null &&
lnks.InnerText.Trim().Length > 0)
select new
{
Url = lnks.Attributes["href"].Value,
Text = lnks.InnerText
Time = lnks. Attributes["time"].Value
};
foreach (var link in linksOnPage)
{
// Loop through.
Response.Write("<link>" + link.Url + "</link>");
Response.Write("<title>" + link.Text + "</title>");
Response.Write("<pubDate>" + link.Time + "</pubDate>");
}
And its not working, I am getting nothing.
So any suggestions and help would be highly appreciated.
Thanks in advance.
Update: I have managed to get the syntax correct now, in order to select the links from the above examples: With the following code:
var linksOnPage = from lnks in document.DocumentNode.SelectNodes("//span[#class='Subject2']//a")
This selects the links nicely with url and text, but how do I go about also getting the time stamp?
That is, select the timestamp out of this:
<span class="time">2012-01-20 09:35</span></a>
which follows each link. And have that output with each link inside the output loop according to the above? Thanks for any help in regards to this.
Your HTML example is malformed, that's why you get unexpected results.
To find your first and second values you'll have to get the <a> inside your <span class='Subject2'> - the first value is a href attribute value, the second is InnerText of the anchor. To get the third value you'll have to get the following sibling of the <span class='Subject2'> tag and get its InnerText.
See, this how you can do it:
var nodes = document.DocumentNode.SelectNodes("//span[#class='Subject2']//a");
foreach (var node in nodes)
{
if (node.Attributes["href"] != null)
{
var link = new XElement("link", node.Attributes["href"].Value);
var description = new XElement("description", node.InnerText);
var timeNode = node.SelectSingleNode(
"..//following-sibling::span[#class='time']");
if (timeNode != null)
{
var time = new XElement("pubDate", timeNode.InnerText);
Response.Write(link);
Response.Write(description);
Response.Write(time);
}
}
}
this outputs something like:
<link>/some/today.nsf/0/EC8A39D274864X5BC125798B0029E305?open</link>
<description>Description 1 text here</description>
<pubDate>2012-01-20 08:35</pubDate>
<link>/some/today.nsf/0/EC8A39XXXX264X5BC125798B0029E312?open</link>
<description>Description 2 text here</description>
<pubDate>2012-01-20 09:35</pubDate>

Resources