Replace text in Word document using .NET Core - .net-core

I have a Word document where I need to replace certain placeholder variables with actual data using .NET Core.
This is the test document that I'm working with. As you can see it currently has two placeholder variables.
The code I have to read a Word document and replace text comes from MSDN using WordprocessingDocument.
await using var stream = new MemoryStream();
stream.Write(template.Blob, 0, template.Blob.Length);
using (var wordDoc = WordprocessingDocument.Open(stream, true))
{
if (wordDoc.MainDocumentPart == null)
{
return null;
}
string docText;
using (var sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
{
docText = await sr.ReadToEndAsync();
}
// Test replacing a variable
Regex regexText = new Regex("{{Building_Current_Version}}");
docText = regexText.Replace(docText, "Some Value");
await using (var sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
await sw.WriteAsync(docText);
}
}
But this doesn't work because the docText output is formatted like this:
<w:r w:rsidR="00287CAD">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:br/>
<w:t>{{</w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r w:rsidR="00287CAD">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>Building_Current_Version</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r w:rsidR="00287CAD">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>}}</w:t>
</w:r>
<w:r w:rsidR="00287CAD">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:br/>
<w:t>{{</w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r w:rsidR="00287CAD">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>Building_Current_ValidUntil</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r w:rsidR="00287CAD">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>}}</w:t>
</w:r>
For some reason the brackets are placed in separate XML tags. But sometimes it doesn't do this. Sometimes it also breaks a variable up in separate XML tags. I'm not adding any formatting to the texts.
So it seems like a simple string replace doesn't work here... Unless there is a way to tell Word not to break up the variables in separate XML tags?
How can I solve this issue?

Related

Xamarin Forms Shell Flyout with Different Title on Tab

I'm making the move from traditional navigation to Shell. Is it possible to have different text on the flyout items vs the tabs? The tab text needs to be short where the flyout could be more descript.
For example, I may have Call for Assistance as the title of the flyout item, but just Call for the tab.
If you want to achieve this effect,you could define FlyoutItem appearance,customize it by setting the Shell.ItemTemplate attached property to a DataTemplate,then let your Label Binding Value Converters to convert the title string:
like:
<Shell>
...
<Shell.Resources>
<ResourceDictionary>
<local:TitlleConverter x:Key="titleConverter" />
</ResourceDictionary>
</Shell.Resources>
<Shell.ItemTemplate>
<DataTemplate>
<Label
Text="{Binding Title,Converter= {StaticResource titleConverter}}"
FontAttributes="Italic"
VerticalTextAlignment="Center" />
</DataTemplate>
</Shell.ItemTemplate>
<FlyoutItem>
<ShellContent Titile ="Call" />
<ShellContent Titile ="" />
<ShellContent Titile ="" />
</FlyoutItem>
</Shell>
the TitlleConverter.cs :
class TitlleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!string.IsNullOrEmpty((string)value) && value.Equals("Call"))
{
return "Call for Assistance";
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

import a complex .docx file as .xml and extract the chapters

--update-- maybe someone can assume another possibility so split a .docxdocument into its chapters, importing .docxto R
first of all, I want to give thanks for this awesome forum. I found several solutions for my upcoming issues.
But this time I haven't found anything...
However, I have a complex .docx document, containing an index, formatted to .xml.
library(XML)
xmlfile <- xmlParse("C:/Users/Documents/stihl.xml", options = HUGE)
topxml <- xmlRoot(xmlfile)
topxml <- xmlSApply(topxml, function(x) xmlSApply(x, xmlValue))
xml_df <- data.frame(t(topxml), row.names = NULL, node)
And other possibilities to read an XML file.
My .docx document has an index and now I want to extract the several index content. As an .docx example
1. Introduction
This is an introduction importing XML by R.
2. UserGuide
Userguides are often helpful.
2.1 Style
The style should be always the same.
2.2 Language
I hope my Language is readable, because I'm contacting you from Germany.
As a result it would be nice to receive the content of the seperated chapters, for example stored in a vector.
result
[1]This is an introduction importing XML by R.
[2]Userguides are often helpful.
[3]The style should be always the same.
[4]I hope my Language is readable, because I'm contacting you from Germany.
Maybe there are other possibilities keeping the structure but I mentioned an XML import containing the tree structure as the easiest way.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
<pkg:part
pkg:name="/_rels/.rels"
pkg:contentType="application/vnd.openxmlformats-package.relationships+xml"
pkg:padding="512">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship
Id="rId3"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
Target="docProps/app.xml"/>
<Relationship
Id="rId2"
Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
Target="docProps/core.xml"/>
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
Target="word/document.xml"/>
</Relationships>
</pkg:xmlData>
</pkg:part>
<pkg:part
#serveral relationships
</pkg:part>
<pkg:part
pkg:name="/word/document.xml"
pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<pkg:xmlData>
<w:document mc:Ignorable="w14 w15 wp14"
xmlns:wpc:http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas
xmlns:mc:http://schemas.openxmlformats.org/markup-compatibility/2006
xmlns:o:urn:schemas-microsoft-com:office:office
xmlns:r:http://schemas.openxmlformats.org/officeDocument/2006/relationships
xmlns:m:http://schemas.openxmlformats.org/officeDocument/2006/math
xmlns:v:urn:schemas-microsoft-com:vml
xmlns:wp14:http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing
xmlns:wp:http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing
xmlns:w10:urn:schemas-microsoft-com:office:word
xmlns:w:http://schemas.openxmlformats.org/wordprocessingml/2006/main
xmlns:w14:http://schemas.microsoft.com/office/word/2010/wordml
xmlns:w15:http://schemas.microsoft.com/office/word/2012/wordml
xmlns:wpg:http://schemas.microsoft.com/office/word/2010/wordprocessingGroup
xmlns:wpi:http://schemas.microsoft.com/office/word/2010/wordprocessingInk
xmlns:wne:http://schemas.microsoft.com/office/word/2006/wordml
xmlns:wps:http://schemas.microsoft.com/office/word/2010/wordprocessingShape
<w:body>
<w:p> ...
</w:p>
<w:p w14:paraId="5BB64FEF" w14:textId="77777777" w:rsidR="005A3789" w:rsidRDefault="005A3789" w:rsidP="005A3789">
<w:pPr>
<w:pStyle w:val="Inhaltsverzeichnisberschrift"/>
</w:pPr>
<w:r>
<w:lastRenderedPageBreak/>
<w:t>Inhaltsverzeichnis</w:t>
</w:r>
</w:p>
'Inhaltsverzeichnis' is the titel of my index. The path is
package -> 3.part -> xmldata -> document -> body -> p
The information is stored here for example
<w:p w14:paraId="15ECF978" w14:textId="77777777" w:rsidR="009B5500" w:rsidRDefault="005A3789">
<w:pPr>
<w:pStyle w:val="Verzeichnis1"/>
<w:rPr>
<w:rFonts w:eastAsiaTheme="minorEastAsia"/>
<w:b w:val="0"/>
<w:noProof/>
<w:color w:val="auto"/>
<w:lang w:eastAsia="de-DE"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:b w:val="0"/>
</w:rPr>
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
<w:instrText xml:space="preserve"> TOC \o "1-4" \h \z \u
</w:instrText>
</w:r>
<w:r>
<w:rPr>
<w:b w:val="0"/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:hyperlink w:anchor="_Toc474825312" w:history="1">
<w:r w:rsidR="009B5500" w:rsidRPr="009D0220"><w:rPr>
<w:rStyle w:val="Hyperlink"/>
<w:noProof/>
</w:rPr>
**<w:t>1</w:t>**
</w:r>
<w:r w:rsidR="009B5500"><w:rPr><w:rFonts w:eastAsiaTheme="minorEastAsia"/>
<w:b w:val="0"/>
<w:noProof/>
<w:color w:val="auto"/>
<w:lang w:eastAsia="de-DE"/>
</w:rPr><w:tab/>
</w:r>
<w:r w:rsidR="009B5500" w:rsidRPr="009D0220">
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
<w:noProof/>
</w:rPr>
**<w:t>Management Summary</w:t>**
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr>
<w:tab/>
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr><w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr>
<w:instrText xml:space="preserve"> PAGEREF _Toc474825312 \h </w:instrText>
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr>
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr>
**<w:t>6</w:t>**
</w:r>
<w:r w:rsidR="009B5500">
<w:rPr>
<w:noProof/>
<w:webHidden/>
</w:rPr>
<w:fldChar w:fldCharType="end"/>
</w:r>
</w:hyperlink>
</w:p>
This is the first entry of the index, 1. Management Summary 6
We can use:
library(xml2)
library(magrittr)
x <- read_xml("path/to/file.xml")
titles <- xml_find_all(x,
"/pkg:package//pkg:part/pkg:xmlData/w:document/w:body/w:p/w:hyperlink/w:r/w:t") %>%
xml_text() %>%
matrix(ncol = 3, byrow = T) %>%
as.data.frame()
colnames(titles)<- c('numChapter', 'title', 'numPage')
This retrives the text inside all the nodes corresponding to that xpath.
Based on your given example that xpath contains (what I suppose are) the numChapter, its title and its numPage.
As noted this will give an error if the xml is not well formed and/or some namespaces are missing.
Hope this helps

How to display this nested array with sub blocks?

Single item of array:
array(3) {
'name' =>
string(19) "trigger_assignments"
'description' =>
string(67) "Maps trigger to hook and operation assignments from trigger.module."
'fields' =>
array(3) {
[0] =>
array(3) {
'name' =>
string(4) "hook"
'description' =>
string(76) "Primary Key: The name of the internal Drupal hook; for example, node_insert."
'type' =>
string(7) "varchar"
}
[1] =>
array(3) {
'name' =>
string(3) "aid"
'description' =>
string(36) "Primary Key: Action's {actions}.aid."
'type' =>
string(7) "varchar"
}
[2] =>
array(3) {
'name' =>
string(6) "weight"
'description' =>
string(67) "The weight of the trigger assignment in relation to other triggers."
'type' =>
string(3) "int"
}
}
}
I can't display 'fields' array. It should be display in table, my code:
[c;block=begin; sub1=(fields)]
Nazwa tabeli: [c.name;]
[c.description;]
Lista pól tabeli:
Nazwa Typ Opis
[c_sub1.name;block=tr] [c_sub1.type;] [c_sub1.description;]
[c;block=end]
The sample result is:
Nazwa tabeli: aggregator_category
Stores categories for aggregator feeds and feed items.
Lista pól tabeli:
Nazwa Typ Opis
[c_sub1.name;block=tr] [c_sub1.type;] [c_sub1.description;]
So table with fields was not displayed.
Could someone give me any advixe?
Code:
$TBS->MergeBlock('c', $table);
$table has items like above inside.
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14" xml:space="preserve">
<w:body>
<w:p w:rsidRDefault="00905443" w:rsidP="00273597">
<w:r>
<w:t>
</w:t>
</w:r>
</w:p>
<w:p w:rsidRDefault="00595A19" w:rsidP="00273597">
<w:r>
<w:t>
Nazwa tabeli: aggregator_category
</w:t>
</w:r>
</w:p>
<w:p w:rsidRDefault="008248E2" w:rsidP="00273597">
<w:r>
<w:t>
Stores categories for aggregator feeds and feed items.
</w:t>
</w:r>
</w:p>
<w:p w:rsidRDefault="00462CAC" w:rsidP="00273597">
<w:r>
<w:t>
Lista pól tabeli:
</w:t>
</w:r>
</w:p>
<w:p w:rsidRDefault="00F53554" w:rsidP="00F53554">
<w:pPr>
<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman" w:hAnsi="Times New Roman"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
</w:rPr>
</w:pPr>
</w:p>
<w:tbl>
<w:tblPr>
<w:tblpPr w:leftFromText="141" w:rightFromText="141" w:vertAnchor="text" w:horzAnchor="margin" w:tblpXSpec="center" w:tblpY="425"/>
<w:tblW w:w="9606" w:type="dxa"/>
<w:tblBorders>
<w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
<w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
</w:tblBorders>
<w:tblLook w:val="01E0" w:firstRow="1" w:lastRow="1" w:firstColumn="1" w:lastColumn="1" w:noHBand="0" w:noVBand="0"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="2440"/>
<w:gridCol w:w="1567"/>
<w:gridCol w:w="5599"/>
</w:tblGrid>
<w:tr w:rsidTr="005C7EBF">
<w:trPr>
<w:trHeight w:hRule="exact" w:val="340"/>
<w:tblHeader/>
</w:trPr>
<w:tc>
<w:tcPr>
<w:tcW w:w="2440" w:type="dxa"/>
<w:shd w:val="clear" w:color="auto" w:fill="C0C0C0"/>
<w:vAlign w:val="center"/>
</w:tcPr>
<w:p w:rsidRDefault="00CE4402" w:rsidP="005E0ABE">
<w:pPr>
<w:spacing w:line="240" w:lineRule="auto"/>
<w:jc w:val="center"/>
<w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>
Nazwa
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="1567" w:type="dxa"/>
<w:shd w:val="clear" w:color="auto" w:fill="C0C0C0"/>
</w:tcPr>
<w:p w:rsidRDefault="00CE4402" w:rsidP="005E0ABE">
<w:pPr>
<w:spacing w:line="240" w:lineRule="auto"/>
<w:jc w:val="center"/>
<w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>
Typ
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="5599" w:type="dxa"/>
<w:shd w:val="clear" w:color="auto" w:fill="C0C0C0"/>
<w:vAlign w:val="center"/>
</w:tcPr>
<w:p w:rsidRDefault="00CE4402" w:rsidP="005E0ABE">
<w:pPr>
<w:spacing w:line="240" w:lineRule="auto"/>
<w:jc w:val="center"/>
<w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>
Opis
</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr w:rsidTr="005C7EBF">
<w:trPr>
<w:trHeight w:hRule="exact" w:val="521"/>
</w:trPr>
<w:tc>
<w:tcPr>
<w:tcW w:w="2440" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidRDefault="005C7EBF" w:rsidP="005C7EBF">
<w:pPr>
<w:spacing w:line="240" w:lineRule="auto"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Verdana" w:eastAsia="Times New Roman" w:hAnsi="Verdana"/>
<w:color w:val="000000"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
<w:t>
[c_sub1.name;block=tr]
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="1567" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidRDefault="005C7EBF" w:rsidP="005C7EBF">
<w:pPr>
<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Verdana" w:eastAsia="Times New Roman" w:hAnsi="Verdana"/>
<w:color w:val="000000"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
<w:t>
[c_sub1.type;]
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="5599" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidRDefault="005C7EBF" w:rsidP="005C7EBF">
<w:pPr>
<w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Verdana" w:eastAsia="Times New Roman" w:hAnsi="Verdana"/>
<w:color w:val="000000"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
<w:t>
[c_sub1.description;]
</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p w:rsidRDefault="00A927EE" w:rsidP="00273597">
<w:pPr>
<w:rPr>
<w:rStyle w:val="Strong"/>
<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana"/>
<w:color w:val="006600"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
<w:shd w:val="clear" w:color="auto" w:fill="FFFFFF"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidRDefault="00905443" w:rsidP="00273597">
<w:r>
<w:rPr>
<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana"/>
<w:color w:val="000000"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
<w:shd w:val="clear" w:color="auto" w:fill="FFFFFF"/>
</w:rPr>
<w:t>
</w:t>
</w:r>
</w:p>
<w:sectPr>
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1417" w:right="1417" w:bottom="1417" w:left="1417" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>
I cannot replicate your result with the information you've given. Using these two test files your data printed like so:
<div>
Name: trigger_assignments<Br>
Maps trigger to hook and operation assignments from trigger.module.
<Br >List:
<table>
<tr>
<td>Nazwa</td>
<td>Typ</td>
<td>Opis</td>
</tr>
<tr>
<td>hook</td>
<td>varchar</td>
<td>Primary Key: The name of the internal Drupal hook; for example, node_insert.</td>
</tr><tr>
<td>aid</td>
<td>varchar</td>
<td>Primary Key: Action's {actions}.aid.</td>
</tr><tr>
<td>weight</td>
<td>int</td>
<td>The weight of the trigger assignment in relation to other triggers.</td>
</tr>
</table>
<br /><br />
</div>
test.php:
$test = array(
array ('name' => "trigger_assignments",
'description' => "Maps trigger to hook and operation assignments from trigger.module.",
'fields' => array(
array('name' => "hook",
'description' => "Primary Key: The name of the internal Drupal hook; for example, node_insert.",
'type' => "varchar"),
array('name' => "aid",
'description' => "Primary Key: Action's {actions}.aid.",
'type' => "varchar"),
array('name' => "weight",
'description' => "The weight of the trigger assignment in relation to other triggers.",
'type' => "int")
)
)
);
include_once('includes/tbs_class.php');
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('test.html');
$TBS->MergeBlock('test', $test);
$TBS->Show();
And test.html:
<div>
[test;block=begin; sub1=(fields)]
Name: [test.name;]<Br>
[test.description;]
<Br >List:
<table>
<tr>
<td>Nazwa</td>
<td>Typ</td>
<td>Opis</td>
</tr>
<tr>
<td>[test_sub1.name;block=tr]</td>
<td>[test_sub1.type;]</td>
<td>[test_sub1.description;]</td>
</tr>
</table>
<br /><br />
[test;block=end]
</div>
Don't know if that helps. Maybe you could give a little more info about your variable 'c' and your $TBS->mergeBlock() command?

How do I create multiple different layouts using only one SiteMap?

Suppose I have 3 areas on my page that have links
Header
Menu
Footer
Each have different links, but some links overlap:
I am using MVCSiteMapProvider to accomplish this. I have a SiteMap:
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0 MvcSiteMapSchema.xsd"
enableLocalization="false">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="Link 1" controller="" action="" visibility="Header, Footer" />
<mvcSiteMapNode title="Link 2" controller="" action="" visibility="Menu" />
<mvcSiteMapNode title="Link 3" controller="" action="" visibility="Header, Menu" />
<mvcSiteMapNode title="Link 4" controller="" action="" visibility="Menu, Footer, Header" />
</mvcSiteMapNode>
</mvcSiteMap>
I thought that maybe Visibility was the way to do this, but it doesn't work the way I want it.
Public Class MenuVisibilityProvider
Implements ISiteMapNodeVisibilityProvider
Public Function IsVisible(ByVal node As SiteMapNode, ByVal context As HttpContext, ByVal sourceMetadata As IDictionary(Of String, Object)) As Boolean Implements ISiteMapNodeVisibilityProvider.IsVisible
Dim visibility As String = node("visibility")
If visibility IsNot Nothing Then Return True
Select Case visibility
Case "Menu"
Case "Header"
Case "Footer"
Return True
End Select
Return False
End Function
End Class
I end up with all of the links in every area.
Edit for clarification:
This is a similar question, but also with no answer:
https://stackoverflow.com/questions/12845929/how-to-show-partial-site-map-including-current-node-with-mvcsitemapprovider
Also similar, but I don't want to have to make multiple SiteMaps: Using Multiple MvcSiteMaps
OP here. I accomplished this using only one site map.
To do this:
I added visibility tags to each sitemap element, for example:
<mvcSiteMapNode title="Login" controller="Members" action="Login" visibility="SideMenu Footer" />
In this example "SideMenu Footer" are my tags. I will use String.Contains() later to determine visibility.
I added multiple different siteMap providers in the Web.config with different siteMapNodeVisibilityProvider:
<siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
<providers>
<clear />
<add name="MvcSiteMapProvider" type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" siteMapFile="~/Mvc.Sitemap" securityTrimmingEnabled="true" cacheDuration="5" enableLocalization="true" scanAssembliesForSiteMapNodes="true" includeAssembliesForScan="" excludeAssembliesForScan="" attributesToIgnore="visibility" nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider" controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider" actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider" aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider" siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider" siteMapNodeVisibilityProvider="MvcSiteMapProvider.DefaultSiteMapNodeVisibilityProvider, MvcSiteMapProvider" siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider" />
<add name="NavSiteMapProvider" ... siteMapNodeVisibilityProvider="RootNamespace.Namespace.NavVisibilityProvider, RootNamespace" ... />
<add name="FooterSiteMapProvider" ... siteMapNodeVisibilityProvider="RootNamespace.Namespace.FooterVisibilityProvider, RootNamespace" ... />
</providers>
</siteMap>
I created a new code file (class) called CustomVisibilityProvider. Inside I created a class for each provider (Footer, Nav, Menu etc)
' Note: VB.NET :P
Public Class MenuVisibilityProvider
Implements ISiteMapNodeVisibilityProvider
Public Function IsVisible(ByVal node As SiteMapNode, ByVal context As HttpContext, ByVal sourceMetadata As IDictionary(Of String, Object)) As Boolean Implements ISiteMapNodeVisibilityProvider.IsVisible
Dim visibility As String = node("visibility")
If visibility Is Nothing Then Return False
If visibility.Contains("Menu") Then Return True
Return False
End Function
End Class
Public Class NavVisibilityProvider
Implements ISiteMapNodeVisibilityProvider
...
If visibility.Contains("Nav") Then Return True
...
End Class
When you're in a view file:
#Html.MvcSiteMap("FooterSiteMapProvider").Menu
Note: You can give the Menu() a custom view also, so that nav, footer, menu etc render the links differently (some might be in <ul></ul> format while others might be <a> tags).

TextArea text is not getting set when in another state

The TextArea.text value is not getting set or staying set. This happens when I have a transition and that uses a Rotate3D and there are two transitions. With one transition it works. With two transitions (the return transition) it doesn't. So in the case below I have a transition from "note" to "list". If I add a transition from "list" to "note" then the behavior occurs. BUT if I put the textArea (note) in both states then it works correctly (ie incluedIn="note,list" works)!
<s:Group id="noteGroup" includeIn="note">
<s:TextArea id="normalTextArea" />
</s:Group>
<s:transitions>
<s:Transition fromState="note" toState="list"
autoReverse="false">
<s:Sequence target="{this}"
duration="{duration}" >
<s:Rotate3D angleYFrom="0" angleYTo="90"
autoCenterTransform="true"
applyChangesPostLayout="true"
/>
<s:SetAction target="{noteGroup}" property="visible" />
<s:RemoveAction target="{noteGroup}" />
<s:AddAction target="{listGroup}"/>
<s:Rotate3D angleYFrom="-90" angleYTo="0"
autoCenterTransform="true"
applyChangesPostLayout="true"/>
</s:Sequence>
</s:Transition>
<s:Transition fromState="list" toState="note"
autoReverse="false"
>
<s:Sequence target="{this}" duration="{duration}" >
<s:Rotate3D angleYFrom="0" angleYTo="-90"
effectStart="trace('rotateStart')"
duration="250"
autoCenterTransform="true"
applyChangesPostLayout="true" />
<s:AddAction target="{noteGroup}"
effectStart="trace('add notes action')"/>
<s:SetAction target="{noteGroup}" property="visible" />
<s:RemoveAction target="{listGroup}"
effectStart="trace('remove lists action')"/>
<s:Rotate3D angleYFrom="90" angleYTo="0"
effectStart="trace('rotateStart 2')"
duration="250"
autoCenterTransform="true"
applyChangesPostLayout="true" />
</s:Sequence>
</s:Transition>
</s:transitions>
~~ UPDATE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A work around I mentioned is to include the textarea in both states and then set the visible to false in the state that it was not originally included in:
<s:Group id="noteGroup"
includeIn="note,list"
visible.list="false">
<s:TextArea id="normalTextArea" />
</s:Group>
~~ UPDATE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Setting the value later (after the transition) works (thanks Flextras) but the text is not visible until I place the cursor in the textarea.
List change handler code:
protected function list1_changeHandler(event:IndexChangeEvent):void {
content = (list.selectedItem as Note).content;
currentState = "note";
setTimeout(setText,1000);
}
private function setText():void {
normalTextArea.text = content; // works but only on clicking into the textarea
}
THIS DOES NOT WORK:
protected function list1_changeHandler(event:IndexChangeEvent):void {
content = (list.selectedItem as Note).content;
normalTextArea.text = content;
trace('1 text ='+normalTextArea.text); // contains content
currentState = "note";
normalTextArea.text = content;
trace('2 text ='+normalTextArea.text); // contains content
setTimeout(setText,1000);
}
// scenario 1
private function setText():void {
normalTextArea.text = content; // clicking into textarea it is empty
}
// scenario 2
private function setText():void {
normalTextArea.text = ""; // this does work but
normalTextArea.text = content; // you have to click into textarea
}

Resources