Docx4j missing borders of table after adding - border

I´ve got a problem while creating a table. Heres my code:
Tbl projectTable = TblFactory.createTable(rows, cols, cellWidthTwips);
Tr tr = (Tr) projectTable.getContent().get(0);
Tc tc = (Tc) tr.getContent().get(0);
tc.getContent().add( this.mainDocument.createParagraphOfText("Cell 1"));
List<Object> lines = mainDocument.getContent();
lines.add(5, projectTable);
The table is added at the wanted position, but without any borders.
When I use the
wordMLPackage.getMainDocumentPart().addObject(projectTable);
method, everything works just fine. The wanted table with borders.
Where is my mistake :(?
EDIT: Here two Links to images of my XML code (can't upload because I don't have enough reputation)
XML Part 1
XML Part 2
And here is the XML code to copy paste:
-<w:p w:rsidP="00CD4679" w:rsidRDefault="00F63A9F" w:rsidR="00CD4679" w:rsidRPr="00CD4679">-<w:pPr>-<w:rPr><w:b/></w:rPr></w:pPr>-<w:r>-<w:rPr><w:b/></w:rPr><w:t>test</w:t></w:r></w:p>-<w:tbl>-<w:tblPr><w:tblW w:w="0" w:type="auto"/><w:tblLook w:val="04A0"/></w:tblPr>-<w:tblGrid><w:gridCol w:w="2017"/><w:gridCol w:w="1473"/><w:gridCol w:w="1451"/><w:gridCol w:w="1492"/><w:gridCol w:w="1423"/><w:gridCol w:w="1432"/></w:tblGrid>-<w:tr w:rsidR="00B94E3A" w:rsidTr="00F63A9F">-<w:tc>-<w:tcPr><w:tcW w:w="2017" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1473" w:type="dxa"/></w:tcPr>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1451" w:type="dxa"/></w:tcPr>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1492" w:type="dxa"/></w:tcPr>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1423" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1432" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc></w:tr>-<w:tr w:rsidR="00B94E3A" w:rsidTr="00F63A9F">-<w:tc>-<w:tcPr><w:tcW w:w="2017" w:type="dxa"/></w:tcPr>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1473" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1451" w:type="dxa"/></w:tcPr>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1492" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1423" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc>-<w:tc>-<w:tcPr><w:tcW w:w="1432" w:type="dxa"/></w:tcPr><w:p w:rsidRDefault="00B94E3A" w:rsidR="00B94E3A"/>-<w:p w:rsidRDefault="00F63A9F" w:rsidR="00B94E3A">-<w:r><w:t>test</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:p w:rsidP="0081364D" w:rsidRDefault="00C46EF4" w:rsidR="00C46EF4"/>-<w:p w:rsidP="0081364D" w:rsidRDefault="00C46EF4" w:rsidR="00C46EF4" w:rsidRPr="00CD4679">-<w:pPr>-<w:rPr><w:b/></w:rPr></w:pPr>-<w:r><w:t>Ende der Vorlage</w:t></w:r></w:p>-<w:sectPr w:rsidR="00C46EF4" w:rsidRPr="00CD4679" w:rsidSect="006C532E"><w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:gutter="0" w:footer="708" w:header="708" w:left="1417" w:bottom="1134" w:right="1417" w:top="1417"/><w:cols w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr>

public static void addBorders(Tbl table)
{
table.setTblPr(new TblPr());
CTBorder border = new CTBorder();
border.setColor("auto");
border.setSz(new BigInteger("4"));
border.setSpace(new BigInteger("0"));
border.setVal(STBorder.SINGLE);
TblBorders borders = new TblBorders();
borders.setBottom(border);
borders.setLeft(border);
borders.setRight(border);
borders.setTop(border);
borders.setInsideH(border);
borders.setInsideV(border);
table.getTblPr().setTblBorders(borders);
}

Related

using cheeriojs to output a specific tag as-is

I am using cheeriojs to parse some xml
const $ = cheerio.load(xml, {
normalizeWhitespace: true,
xmlMode: true
})
This is probably something very basic that eludes me, but I can't figure out how to output the selected element verbatim. For example, I have
<foo id="3B3D3CAD1268FFDFD3E36F2DFD30DBD0" a="3392779302" b="Chiapas" c="Mexico">
<emphasis bold="true" pageId="3" pageNumber="120">Type locality.</emphasis>
</foo>
<emphasis bold="true" pageId="3" pageNumber="120">Other localities.</emphasis>
<foo id="3B3D3CAD1268FFDFD3E36F2D68FFDFD" a="3392779378" b="Baja California" c="Mexico">
<emphasis bold="true" pageId="3" pageNumber="120">Type locality.</emphasis>
</foo>
and I have selected the above like so
const elements = $('foo')
for (let i = 0; i < elements.length; i++) {
const e = elements[i]
console.log($(e).html())
}
I get
<emphasis bold="true" pageId="3" pageNumber="120">Type locality.</emphasis>
<emphasis bold="true" pageId="3" pageNumber="120">Type locality.</emphasis>
But I want
<foo id="3B3D3CAD1268FFDFD3E36F2DFD30DBD0" a="3392779302" b="Chiapas" c="Mexico"></foo>
<foo id="3B3D3CAD1268FFDFD3E36F2D68FFDFD7" a="3392779378" b="Baja California" c="Mexico"></foo>
console.log($(e).prop('outerHTML')) does the trick

Use Tampermonkey/Userscript to organise UL List

I am trying to order my search results using TamperMonkey/Userscript. The results start with Customer:, Case:, Inventory:, PNG:, etc. Below is HTML from the search results however I cannot find anyway to customise the order on these??
<div class="uir-tooltip-content"><ul id="uir-global-search-container" role="listbox" style="min-width: 550px; display: block;"><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=3904965" id="/app/common/media/mediaitem.nl?id=3904965">PNG Image: <span>Bank Transfer Receipt Thermo Invoice 67578.PNG</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=3904965&e=T" id="edit_/app/common/media/mediaitem.nl?id=3904965" aria-label="Edit PNG Image:Bank Transfer Receipt Thermo Invoice 67578.PNG">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=4380864" id="/app/common/media/mediaitem.nl?id=4380864">PNG Image: <span>Bank Transfer Receipt Thermo Invoice 71546.PNG</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=4380864&e=T" id="edit_/app/common/media/mediaitem.nl?id=4380864" aria-label="Edit PNG Image:Bank Transfer Receipt Thermo Invoice 71546.PNG">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=4230494" id="/app/common/media/mediaitem.nl?id=4230494">PNG Image: <span>Bank Transfer Receipt Thermo January Invoices.PNG</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=4230494&e=T" id="edit_/app/common/media/mediaitem.nl?id=4230494" aria-label="Edit PNG Image:Bank Transfer Receipt Thermo January Invoices.PNG">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=5049467" id="/app/common/media/mediaitem.nl?id=5049467">PDF File: <span>BOQ IB - Transfers & BPAY - Thermogroup.pdf</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=5049467&e=T" id="edit_/app/common/media/mediaitem.nl?id=5049467" aria-label="Edit PDF File:BOQ IB - Transfers & BPAY - Thermogroup.pdf">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=5168179" id="/app/common/media/mediaitem.nl?id=5168179">PDF File: <span>BOQ IB - Transfers & BPAY THERMO.pdf</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=5168179&e=T" id="edit_/app/common/media/mediaitem.nl?id=5168179" aria-label="Edit PDF File:BOQ IB - Transfers & BPAY THERMO.pdf">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/common/media/mediaitem.nl?id=5661633" id="/app/common/media/mediaitem.nl?id=5661633">PDF File: <span>BOQ IB - Transfers & BPAY.pdf</span></a><a class="uir-item-edit" href="/app/common/media/mediaitem.nl?id=5661633&e=T" id="edit_/app/common/media/mediaitem.nl?id=5661633" aria-label="Edit PDF File:BOQ IB - Transfers & BPAY.pdf">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1056272" id="/app/crm/common/crm.nl?id=1056272">Case: <span>C10118 You've been sent the details of a NetBank tra... (3077 Ascot Bathroomware)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1056272&e=T" id="edit_/app/crm/common/crm.nl?id=1056272" aria-label="Edit Case:C10118 You've been sent the details of a NetBank tra... (3077 Ascot Bathroomware)">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1262175" id="/app/crm/common/crm.nl?id=1262175">Case: <span>C12226 You've been sent the details of a NetBank tra... (2268 Tile Power Penrith)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1262175&e=T" id="edit_/app/crm/common/crm.nl?id=1262175" aria-label="Edit Case:C12226 You've been sent the details of a NetBank tra... (2268 Tile Power Penrith)">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1395573" id="/app/crm/common/crm.nl?id=1395573">Case: <span>C13603 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1395573&e=T" id="edit_/app/crm/common/crm.nl?id=1395573" aria-label="Edit Case:C13603 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)">Edit</a></li><li class="uir-global-search-item"><a role="option" class="uir-item-view" href="/app/crm/common/crm.nl?id=1624647" id="/app/crm/common/crm.nl?id=1624647">Case: <span>C15969 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)</span></a><a class="uir-item-edit" href="/app/crm/common/crm.nl?id=1624647&e=T" id="edit_/app/crm/common/crm.nl?id=1624647" aria-label="Edit Case:C15969 You've been sent the details of a NetBank tra... (0378 Solartex Insulation)">Edit</a></li><li><a id="showMoreItems" class="uir-item-view uir-global-search-more" href="/app/common/search/ubersearchresults.nl?Uber_NAME=transfer&quicksearch=T&searchtype=Uber&frame=be&Uber_NAMEtype=KEYWORDSTARTSWITH">Show more results</a></li></ul></div>
I guess it's not the best way to do it, but you could try something like this:
// ==UserScript==
// #name New Userscript
// #namespace http://tampermonkey.net/
// #version 0.1
// #description try to take over the world!
// #author You
// #match https://www.w3schools.com/jsref/dom_obj_document.asp
// #icon https://www.google.com/s2/favicons?domain=w3schools.com
// #grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
var UL = document.getElementById("uir-global-search-container");
if (UL.hasChildNodes()) {
var LIs = Array.from(UL.getElementsByClassName("uir-global-search-item"));
var newLIs;
LIs.forEach(li => {
UL.removeChild(li);
});
var moreLink = UL.lastChild;
UL.removeChild(moreLink);
LIs.forEach(li => {
if(li.innerHTML.includes("Customer:")) {UL.appendChild(li); }
});
LIs.forEach(li => {
if(li.innerHTML.includes("Case:")) UL.appendChild(li);
});
LIs.forEach(li => {
if(li.innerHTML.includes("Inventory:")) UL.appendChild(li);
});
LIs.forEach(li => {
if(li.innerHTML.includes("PNG Image:")) UL.appendChild(li);
});
LIs.forEach(li => {
if(li.innerHTML.includes("PDF File:")) UL.appendChild(li);
});
UL.appendChild(moreLink);
}
})();

replace space in text without affecting html tags

I need to replace the space inside the html by , but without affecting the spaces inside of .
So that something like this: Hello <font color="red"> How Are <font color="black"> You?
would become this: Hello <font color="red"> How Are <font color="black"> You?
It changes the spaces outside of the tags, but the spaces inside the tags aren't affected.
I have tried this sample code that was suggested by someone:
NSString *string = originalHTMLString;
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:#"(?i)(<script(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</script\\s*>|<style(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</style\\s*>|<textarea(?:[^>\"']|\"[^\"]*\"]|'[^']*')*>)\s+</textarea\\s*>|</?[a-z](?:[^>\"']|\"[^\"]*\"]|'[^']*')*>|\\S+)|\\s+" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:#" "];
finalHTMLString = modifiedString;
But it didn't work. Just returned Null, I think the RegEx pattern is wrong.
This is some sample html I have to convert:
<samp class="s22">من مشاكل جرّأء العثّ والفيروسات منذ سنوات. إلاّ أنّ أمرًا ما حدث في الأعوام الماضية وسبّب المشكلة".</samp></p> <p class="mytext-19" dir="RTL"><samp class="s20">ويعتقد هاكينبرغ أنّ الأمر بدأ منذ عام </samp><samp class="s21">2004</samp><samp class="s22">. ففي أيار ذلك العام، اشتكى مزارعو العنبيّة في ماين من أنّ نحلهم الذي يلقّح محصولهم كان يُنتج طرودًا ويغادر الخلايا. كما أنّ نحل الخلايا الأخرى لا يسرق العسل الموجود في الخليّة المتروكة.</samp></p> <p class="mytext-19" dir="RTL"><samp class="s20">وحين بحث عن تفسير لهذا السلوك الغريب، اكتشف أنّ مزارعي التفاح في واشنطن استعملوا مبيدًا جديدًا يحتوي على النيونيكوتينوييد يُدعى </samp><samp dir="LTR">Assail</samp><samp class="s22"> لأشجارهم. وكان نحله يلقّح تلك الأشجار في الربيع.</samp></p> <p class="mytext-19" dir="RTL"><samp class="s20">ذاك الشتاء (</samp><samp class="s21">2004</samp><samp class="s22">-</samp><samp class="s21">2005</samp><samp class="s22">)، خسر ثلثَ نحله تقريبًا، وهي نسبة أعلى بكثير من المعتاد. وفي العام التالي نفق النصف كما أُبلغ عن خسائر في مختلف أنحاء البلاد.</samp></p> <p class="mytext-19" dir="RTL"><samp class="s20">يقول هاكنبيرغ: "لقد ساءت الأمور جدًّا، ولكنّ أحدًا لم يتمكّن <samp class="s37">من معرفة السبب". لهذا، ففي صيف عام </samp></samp><samp class="s61">2006</samp><samp class="s38"> عقد اجتماعًا مع علماء في نبراسكا ليحاول إيجاد سبب للارتفاع السريع في معدّل نفوق </samp><samp class="s26">النحل. "قيل إنّ الاجتماع ضمّ أذكى العقول ولكنّنا جلسنا ليومين نتباحث من دون التوصّل لشيء". وبعد بضعة أشهر هلك ثلثا ما تبقّى من نحله.</samp></p> <p class="mytext-19" dir="RTL"><samp class="s20">أعطى النحّالون الذين نقلوا </samp><samp class="s21">1</samp><samp class="s22">.</samp><samp class="s21">2</samp><samp class="s22"> مليون قفير إلى بساتين اللوز في كاليفورنيا في شباط أوّل مؤشر على صحة النحل عام </samp><samp class="s21">2008</samp><samp class="s22">. لم تكن الإشارات جيّدة. <a class="MyAppHighlight1" style="background-color:pink; color:black;" name="M10">فمن بين الاثني عشر نحّالاً تقريبًا الذين تحدثنا إليهم</a>، اثنان منهم فقط دخلوا الشتاء سالمين نسبيًّا. أمّا الباقون فخسروا ما يتراوح بين </samp><samp class="s21">30</samp><samp class="s22"> بالمئة و</samp><samp class="s23">60</samp><samp class="s22"> بالمئة من قفرلوا الشتاء سالمين نسبيًّا. أمّا الباقون فخسروا ما يتراوح بين </samp><samp class="s21">30</samp><samp class="s22"> بالمئة و</samp><samp class="s23">60</samp><samp class="s22"> بالمئة من قفر\330انهم بما بدا شبيهًا بداء <samp class="s37">انهيار الخليّة. ومن بين عمليات الهجرة الاثنتي عشرة التي تابعتها وزارة </samp>الزراعة الأميركيّة من أيلول <samp class="s37">العام </samp></samp><samp class="s21">2007</samp><samp class="s22"> وحتّى ربيع <samp class="s37">العام </samp></samp><samp class="s21">2008</samp><samp class="s22">، ظهر في خمس </samp><samp dir="LTR" class="s2"><span style="display:none;">00002</span> </samp><a style="color:transparent;" name="00003"></a><samp><span style="display:none;">00003</span></samp></p> <p class="bigtitle"> </p> <p class="bigtitle"> </p> <p class="bigtitle-3" dir="RTL"><samp class="s4">عَالَمٌ بِلا نَحْل</samp></p> <p class="bigtitle-3" dir="RTL"><samp dir="LTR" class="s5">A World Without Bees</samp></p> <p class="mo2allef"> </p> <p class="mo2allef"> </p> <p class="smallertitleCxSpFirst-6" dir="RTL"><samp class="s7">تأليف</samp><samp class="s8">:</samp></p><p> </p>
Thank you for your assistance.
This isn't a RegEx answer, but in Objective-C this should take a string called originalHTML, switch out all of the spaces outside of tags, and save it as a string called finalHTML
NSString *originalHTML = #"Your backslashed HTML Here";
NSString *finalHTML = [[NSMutableString alloc] init];
BOOL insideTag = NO;
BOOL convertSpace = NO;
for (int i = 0; i < originalHTML.length; i++) {
unichar uniCharacter = [originalHTML characterAtIndex:i];
if ([[NSString stringWithFormat:#"%C", uniCharacter] isEqualToString:#"<"]) {
insideTag = YES;
}
if ([[NSString stringWithFormat:#"%C", uniCharacter] isEqualToString:#">"]) {
insideTag = NO;
}
if (!insideTag) {
if ([[NSString stringWithFormat:#"%C", uniCharacter] isEqualToString:#" "]) {
convertSpace = YES;
}
}
if (!convertSpace) {
finalHTML = [finalHTML stringByAppendingFormat:[NSString stringWithFormat:#"%C", uniCharacter]];
} else {
finalHTML = [finalHTML stringByAppendingFormat:#" "];
convertSpace = NO;
}
}
NSLog(#"%#", finalHTML);
*Note, this will not work if you just have a less than sign or greater than sign in your html body that is not part of a tag. If you need to write Less Than< or Greater Than> In your actual body text please use < or >

MVVMCross Code Snippets for Visual Studio?

where can I download the snippets for Visual Studio, the likes pf pmvx, cmvx and others?
I though those would be available on the github projects, but can't find them...
I've already created my own. Please remember that these are ReSharper's template.
mvxcom -> for Command
#region $region$ command
private MvxCommand _$NAME$Command;
public ICommand $PNAME$Command
{
get
{
_$NAME$Command = _$NAME$Command ?? new MvxCommand(Do$PNAME$Command);
return _$NAME$Command;
}
}
private void Do$PNAME$Command()
{
$END$
}
#endregion
mvxprop -> for Properties
#region $region$
private $TYPE$ _$NAME$;
public $TYPE$ $PNAME$
{
get { return _$NAME$; }
set { _$NAME$ = value; RaisePropertyChanged(() => $PNAME$); }
}
#endregion
$END$
mvxset -> Binding Set
var set = this.CreateBindingSet<$VIEW$, $VIEW$Model>();
set.Bind($ELEMENT$).To(vm => vm$END$);
set.Apply();
You can add them to your ReSharper using ReSharper>Template Explorer>Live Templates>New Template.
Please feel free to change them however you desire.
And here's the native VS version of the snippets based on Aboo's answer above.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvxprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { if($backingfield$ == value) return; $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Command</Title>
<Description>Insert a Command declaration for an MvvMCross View Model</Description>
<Shortcut>mvxcom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$Command = $backingfield$Command ?? new MvxCommand(Do$Name$Command);
return $backingfield$Command;
}
}
private void Do$Name$Command()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvxset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
If I'm correct in my presumption, you're referring to the shortcuts that Stuart uses in his demos for MvvmCross. These are snippets of code that he has written and assigned to shortcuts using ReSharper and are not publicly available, though if you asked nicely they can be exported and shared. Of course you could always make your own 'Live Template' using this tutorial
I modified #Coasty's answer to include an async command adapted from https://stackoverflow.com/questions/17187113/how-can-i-use-async-in-an-mvvmcross-view-model and changed the shortcuts so they no longer collide with the mvx namespaces.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvvmcrossprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Command</Title>
<Description>Insert a Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrosscom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(Do$Name$);
return $backingfield$;
}
}
private void Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Async Command</Title>
<Description>Insert an Async Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrossacom</Shortcut>
<Author>Benjamin Hysell (based on Andrew Coates Command Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(async () => await Do$Name$());
return $backingfield$;
}
}
private async Task Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvvmcrossset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

How to obtain href values from a div using xpath?

I have a div like this:
<div class="widget-archive-monthly widget-archive widget">
<h3 class="widget-header">Monthly Archives</h3>
<div class="widget-content">
<ul>
<li>October 2010</li>
<li>September 2010</li>
<li>August 2010</li>
<li>July 2010</li>
<li>June 2010</li>
<li>May 2010</li>
<li>April 2010</li>
<li>March 2010</li>
<li>February 2010</li>
<li>January 2010</li>
<li>December 2009</li>
<li>November 2009</li>
<li>October 2009</li>
<li>September 2009</li>
<li>August 2009</li>
<li>July 2009</li>
<li>June 2009</li>
<li>May 2009</li>
<li>April 2009</li>
<li>March 2009</li>
<li>February 2009</li>
</ul>
</div>
</div>
I'm trying to get the href values inside the widget-content div.
How would I target these links using xpath and ignore any other link on the page such as the one for "Archives" so that I end up just with these values:
http://myblog.com/blogs/my_name/2010/10/
http://myblog.com/blogs/my_name/2010/09/
http://myblog.com/blogs/my_name/2010/08/
http://myblog.com/blogs/my_name/2010/07/
... etc ...
//div[#class="widget-content"]//a/#href
That should give you the href values of links that are ONLY inside the widget-content DIV.
relative answer = XPath: find link URL by link text
"//a/#href"