kris_4_forums

Hi there,

I have custom xml data like below inside item1.xml which is mapped to a richt text content control:

<address>Mr.\r\n Kamran King\r\n81 Newgate Street\r\nLondon</address>

I inserted "\r\n" for line breaks. How can I display it in multiple lines in side this rich text control.

Any help is greatly appreciated.

TIA,

Kris



Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

Lanqing Brownell

Hi Kris, have you tried to map the \r\n into <w:br/> in the text





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

kris_4_forums

Hello Lanqing,

Yes, But Word did not interpret the <w:t> <w:br/>some text <w:t/> tags & diplay it as if a text.





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

Lanqing Brownell

Have you tried to put <w:br/> outside <w:t> element, as below:

<w:r><w:br/><w:t>some text</w:t></w:r>

In rich text control, this will put the text "some text" into a new line.





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

kris_4_forums

Hi Lanqing,

Neither keeping the above text in CDATA section of item1.xml nor pasting it directly to content control worked as expected.

Was it working when you tried. If yes then what else did you configured i.e properties of content contrl.





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

Wouter van Vugt

Hi Kris,

to allow multiple lines of text and databinding use normal carriage-return newline tags. You can easily get a good sample of how the XML should look by using Word. (I can send a valid document, but using these steps you can create your own).

First crank up Word and create a new empty document. Add a plain-text control to the document (rich text controls cannot data-bind)

Next go to the developer tab and open Visual Basic.

Create and run a new method with the following code:

Sub test()

Dim part As CustomXMLPart
Set part = Application.ActiveDocument.CustomXMLParts.Add("<root><text/></root>")
Call Application.ActiveDocument.ContentControls.Item(1).XMLMapping.SetMapping("/root/text", , part)

End Sub

Open the document in Package Explorer and save the Item1.xml file to disc and open the binary. The following sequence contains a few characters (asasdsadasd) and a newline, some characters again. The lines are delimited using a carriage return-newline combo ( 0D 0A in hex)

<root><text>asdasdasd
asdsad
sad
as
dsa
dsa
da</text></root>

Hope it helps,

Wouter





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

kris_4_forums

Hello Wouter,

Thank you very much for your answer.

--to allow multiple lines of text and databinding use normal carriage-return newline tags.

--Open the document in Package Explorer and save the Item1.xml file to disc and open the binary. The following sequence contains a few characters (asasdsadasd) and a newline, some characters again. The lines are delimited using a carriage return-newline combo ( 0D 0A in hex)

Being a newbie, I couldn't understand & follow the above steps.

Do I have to edit the text in item1.xml with carriage-return newline tags. When I used a plain text control, ran the above vb code & replaced the item1.xml text with the above, I get a non editable text inside content control like this: asdasdasdasdsadsadasdsadsada

Regards,

Kris





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

Lanqing Brownell

Hi Kris,

The Package Explorer that Wouter mentioned is a tool to view the OpenXml documents based on Open Package Convention (aka. OPC the ECMA spec part 2). You could try that way, or you could simply rename the "document.docx" file to "document.zip". Then you should be able to isolate out the item1.xml or document.xml (whatever the name is, it is the xml file where your content control lies). Once you have the item1.xml file, you could open it in binary format and insert the 0D 0A as Wouter suggested.

I have not tried that way myself. What I've tried is to directly manipulate the item1.xml, in the fragment that define the content control, within the run, add an element <w:br/> between the <w:t> elements. Then WORD will display text in multiple lines. The following is a working example:

<wTongue Tieddt>
<wTongue TieddtPr>
<w:id w:val="1568465755"/>
<wStick out tonguelaceholder>
<wBig SmileocPart w:val="D43DC60C29474204B65B2DE33BF1F29E"/>
</wStick out tonguelaceholder>
<w:text/>
</wTongue TieddtPr>
<wTongue TieddtContent>
<w:r w:rsidR="009355E1">
<w:rPr>
<w:rFonts w:hint="eastAsia"/>
</w:rPr>
<w:t>Text. Need to add a new line.</w:t>
<w:br/>
<w:t>This line starts from a new line.</w:t>
</w:r>
</wTongue TieddtContent>
</wTongue Tieddt>
Ignore all the details about describing the plan text control, just note the parts being highlighted.

Also, please note that for Rich Text Controls, WORD UI allows user to insert a new line by "shift-enter". WORD UI does not support this with plain Text Control and other content controls. You will need directly manipulate the XML fragments.

Hope this helps.





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

PradeepPo

On the same note -

I am really surprised that there are no questions from anyone about Rich text content controls and getting formatted HTMLs out of that.

I am not sure if I am alone in this space but : we have a document with let's say 50 rich text content controls. Well we don't really have a way to repeat these content controls by directly tying it to a XML file but have to do it programmatically. 2) when the rich text content control is bound we lost the formatting feature 3) if i want to get the HTML output of what the user entered (they want Word for all the differnt option it provides and they are in familiar desktop tools) in each rich text content control without programmatically creating an HTML file for each content control (one-to-one leading to about 50 htmls) 4) THERE GOT TO BE A WAY!

Any thoughts. Personally I think this is a blunder from MS - they removed HtmlProject support in '07 and we can't do this in memory and we have to physically create these files. also I can't understand the reasoning on why rich text content control can't be bound. People use word primarily to prepare content WITH formatting and MS supports text only when bound.

Either I am missing something or MS missed something here. Thoughts / suggestions welcome.

- Pradeep






Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

PKordes

Help,

I have the exact same question about getting HTML from a Content Control. I can get the XML, but it seems nearly impossible to transform it. I tried some of the xslt that are out there, but they seem to only work on a whole document.

Please help.

Paul Kordes





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

Crusjiber

There is a property setting for the content control you can turn on in Word 2007: "Allow carraige return (multiple paragraph)". I did turn it on and my formatted address could be displayed correctly (the address was coming out of customXMLPart).

Hope this help.

Crusjiber





Re: Microsoft SDK for Open XML Formats Display cutom xml text in multiple lines inside a Rich text content control in Word 2007.

Harry Sauers

Thanks Crusjiber.

I had the same exact problem and this fixed it. In code, I just set the MultiLine property of the plain text content control to true and the line breaks appeared as expected in the XML-mapped content control. Apparently, this property is set to false by default; if it is not explicitly set to true, any line breaks ("\r\n") in the mapped data will be ignored.

Thanks again!

-Harry