What i am doing is to pull the data from a CMS and import it to Word
2007 Beta and i also have to export the data from Word 2007 Beta back
to that CMS. We have with us two Web Services of the CMS. The Web
Services are explained as follows:
IMPORT WEB SERVICE:
1) This web service pulls the entire data from a particular page
of CMS and returns an XHTML string.
2) I use this web service to grab this XHTML content in a string.
The code to achieve this is given below:
String newEntireRichContent =
objwsRichContent.GetRichTextContent(frmServer.auth enticationToken,
node);
"objwsRichContent.GetRichTextContent()" is a web service method
which takes 2 parameters i.e. the "authenticationToken" and
"node". Here "node" is the page number. Based on this page
number the web service returns the entire text on that page in the form
of XHTML string. I take this content in a "string" variable
(newEntireRichContent).
3) Now I create a Word Range object as follows:
Word.Range currentRange =
Globals.ThisAddIn.Application.Selection.Range;
4) After making the word range object, I assign the XHTML string
to it as follows:
currentRange.Text = newEntireRichContent;
5) Now,what I get on the word document is the origninal
text,something like this:
<p align="left"><strong><span style="COLOR: #ff0000">Synkron Via CMS<br
/></span><span style="COLOR: #008000">This is a new text for services
page.<br /></span><span style="COLOR: #0000ff"><em><u>The main idea
behind developing this text is to test the web services.<br /><br
/></u></em></span></strong></p><h1>FORMULA<strong><span style="COLOR:
#0000ff"><br />(a+b)<sup>2</sup>=(a<sup>2</sup>+2ab+b<
and so on.....
6) But what I want is that instead of giving pure XHTML string. It
should be able to present the data in a formatted way based on the tags
present in the XHTML string. For example the heading tag should present
the data in a form of a heading and not with <h1tags. the texts
between the <b></btags should be bold and so on.
7) Once import is implemented properly I want the same to happen
with the EXPORT functionality. In the export functionality it should
take the data from Word 2007 and then convert it into properly formed
XHTML string.
Could anybody please provide some help that how this can be achieved ?
I have posted this into multiple groups as i dont really know which
group would be the right one for this.
the complete code is provided below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using mshtml;
using Word = Microsoft.Office.Interop.Word;
using ContentWebService = global::Synkronv10.ContentWebService;
//Content WebService
using SiteStructureWebService =
global::Synkronv10.SiteStructureWebService; //Site Structure WebService
namespace Synkronv10
{
public partial class frmImport : Form
{
public static string entireRichContent;
public static string selectedNode;
public static int node;
public frmImport()
{
InitializeComponent();
}
#region PopulatingTree
#region Form Load Function
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmImport_Load(object sender, EventArgs e)
{
try
{
// SECTION 1. Create a DOM Document and load the
XML data into it.
XmlDocument dom = new XmlDocument();
SiteStructureWebService.SiteStructure
objwsStructure = new
Synkronv10.SiteStructureWebService.SiteStructure() ;
string xml =
objwsStructure.GetStructureXML(frmServer.authentic ationToken);
dom.LoadXml(xml);
// SECTION 2. Initialize the TreeView control.
treeView1.Nodes.Clear();
treeView1.Nodes.Add(new
TreeNode(dom.DocumentElement.Name));
TreeNode tNode = new TreeNode();
tNode = treeView1.Nodes[0];
// SECTION 3. Populate the TreeView with the DOM
nodes.
AddNode(dom.DocumentElement, tNode);
treeView1.ExpandAll();
}
catch { }
}
#endregion
private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;
int i;
// Loop through the XML nodes until the leaf is reached.
// Add the nodes to the TreeView during the looping
process.
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for (i = 0; i <= nodeList.Count - 1; i++)
{
xNode = inXmlNode.ChildNodes[i];
inTreeNode.Nodes.Add(new TreeNode(xNode.Name));
tNode = inTreeNode.Nodes[i];
AddNode(xNode, tNode);
if (xNode.Name.ToLower() == "page")
{
tNode.Tag =
xNode.Attributes["ElementId"].Value.ToString();
tNode.Text =
xNode.Attributes["Name"].Value.ToString();
}
if (tNode.Text.StartsWith("<![CDATA"))
{
int sIndex = ((tNode.Text.IndexOf("[", 3))+ 1);
int eIndex = tNode.Text.IndexOf("]", sIndex);
tNode.Text = tNode.Text.Substring(sIndex,
(eIndex - sIndex)); //Showing the Inner text of CDATA tag
}
}
}
else
{
// Here you need to pull the data from the XmlNode
based on the
// type of node, whether attribute values are required,
and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim();
}
}
#endregion
private void btnImport_Click(object sender, EventArgs e)
{
try
{
selectedNode = treeView1.SelectedNode.Tag.ToString();
//Populating the Word document with text through
WebService
ContentWebService.Content objwsRichContent = new
Synkronv10.ContentWebService.Content();
entireRichContent =
objwsRichContent.GetPageContentXML(frmServer.authe nticationToken,
Convert.ToInt32(selectedNode));
XmlDocument objXML = new XmlDocument();
objXML.LoadXml(entireRichContent);
string newEntireRichContent = string.Empty;
//Taking out the first element from the document
XmlNodeList objNode =
objXML.GetElementsByTagName("ContentElement");
node =
Convert.ToInt32(objNode.Item(0).Attributes["ElementId"].Value);
newEntireRichContent =
objwsRichContent.GetRichTextContent(frmServer.auth enticationToken,
node);
Word.Range currentRange =
Globals.ThisAddIn.Application.Selection.Range;
currentRange.Text = newEntireRichContent;
frmImport.ActiveForm.Visible= false;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
frmImport.ActiveForm.Visible = false;
}
private void treeView1_AfterSelect(object sender,
TreeViewEventArgs e)
{
}
}
} 1 4028
I'd try posting this to microsoft.public.dotnet.languages.csharp.
It's a much more active newsgroup, and you'll probably get some help
there.
Robin S.
---------------------------
"Darsin" <da****@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
What i am doing is to pull the data from a CMS and import it to Word
2007 Beta and i also have to export the data from Word 2007 Beta back
to that CMS. We have with us two Web Services of the CMS. The Web
Services are explained as follows:
IMPORT WEB SERVICE:
1) This web service pulls the entire data from a particular page
of CMS and returns an XHTML string.
2) I use this web service to grab this XHTML content in a string.
The code to achieve this is given below:
String newEntireRichContent =
objwsRichContent.GetRichTextContent(frmServer.auth enticationToken,
node);
"objwsRichContent.GetRichTextContent()" is a web service method
which takes 2 parameters i.e. the "authenticationToken" and
"node". Here "node" is the page number. Based on this page
number the web service returns the entire text on that page in the
form
of XHTML string. I take this content in a "string" variable
(newEntireRichContent).
3) Now I create a Word Range object as follows:
Word.Range currentRange =
Globals.ThisAddIn.Application.Selection.Range;
4) After making the word range object, I assign the XHTML string
to it as follows:
currentRange.Text = newEntireRichContent;
5) Now,what I get on the word document is the origninal
text,something like this:
<p align="left"><strong><span style="COLOR: #ff0000">Synkron Via
CMS<br
/></span><span style="COLOR: #008000">This is a new text for services
page.<br /></span><span style="COLOR: #0000ff"><em><u>The main idea
behind developing this text is to test the web services.<br /><br
/></u></em></span></strong></p><h1>FORMULA<strong><span style="COLOR:
#0000ff"><br />(a+b)<sup>2</sup>=(a<sup>2</sup>+2ab+b<
and so on.....
6) But what I want is that instead of giving pure XHTML string.
It
should be able to present the data in a formatted way based on the
tags
present in the XHTML string. For example the heading tag should
present
the data in a form of a heading and not with <h1tags. the texts
between the <b></btags should be bold and so on.
7) Once import is implemented properly I want the same to happen
with the EXPORT functionality. In the export functionality it should
take the data from Word 2007 and then convert it into properly formed
XHTML string.
Could anybody please provide some help that how this can be achieved ?
I have posted this into multiple groups as i dont really know which
group would be the right one for this.
the complete code is provided below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using mshtml;
using Word = Microsoft.Office.Interop.Word;
using ContentWebService = global::Synkronv10.ContentWebService;
//Content WebService
using SiteStructureWebService =
global::Synkronv10.SiteStructureWebService; //Site Structure
WebService
namespace Synkronv10
{
public partial class frmImport : Form
{
public static string entireRichContent;
public static string selectedNode;
public static int node;
public frmImport()
{
InitializeComponent();
}
#region PopulatingTree
#region Form Load Function
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmImport_Load(object sender, EventArgs e)
{
try
{
// SECTION 1. Create a DOM Document and load the
XML data into it.
XmlDocument dom = new XmlDocument();
SiteStructureWebService.SiteStructure
objwsStructure = new
Synkronv10.SiteStructureWebService.SiteStructure() ;
string xml =
objwsStructure.GetStructureXML(frmServer.authentic ationToken);
dom.LoadXml(xml);
// SECTION 2. Initialize the TreeView control.
treeView1.Nodes.Clear();
treeView1.Nodes.Add(new
TreeNode(dom.DocumentElement.Name));
TreeNode tNode = new TreeNode();
tNode = treeView1.Nodes[0];
// SECTION 3. Populate the TreeView with the DOM
nodes.
AddNode(dom.DocumentElement, tNode);
treeView1.ExpandAll();
}
catch { }
}
#endregion
private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;
int i;
// Loop through the XML nodes until the leaf is reached.
// Add the nodes to the TreeView during the looping
process.
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for (i = 0; i <= nodeList.Count - 1; i++)
{
xNode = inXmlNode.ChildNodes[i];
inTreeNode.Nodes.Add(new TreeNode(xNode.Name));
tNode = inTreeNode.Nodes[i];
AddNode(xNode, tNode);
if (xNode.Name.ToLower() == "page")
{
tNode.Tag =
xNode.Attributes["ElementId"].Value.ToString();
tNode.Text =
xNode.Attributes["Name"].Value.ToString();
}
if (tNode.Text.StartsWith("<![CDATA"))
{
int sIndex = ((tNode.Text.IndexOf("[", 3))+ 1);
int eIndex = tNode.Text.IndexOf("]", sIndex);
tNode.Text = tNode.Text.Substring(sIndex,
(eIndex - sIndex)); //Showing the Inner text of CDATA tag
}
}
}
else
{
// Here you need to pull the data from the XmlNode
based on the
// type of node, whether attribute values are required,
and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim();
}
}
#endregion
private void btnImport_Click(object sender, EventArgs e)
{
try
{
selectedNode = treeView1.SelectedNode.Tag.ToString();
//Populating the Word document with text through
WebService
ContentWebService.Content objwsRichContent = new
Synkronv10.ContentWebService.Content();
entireRichContent =
objwsRichContent.GetPageContentXML(frmServer.authe nticationToken,
Convert.ToInt32(selectedNode));
XmlDocument objXML = new XmlDocument();
objXML.LoadXml(entireRichContent);
string newEntireRichContent = string.Empty;
//Taking out the first element from the document
XmlNodeList objNode =
objXML.GetElementsByTagName("ContentElement");
node =
Convert.ToInt32(objNode.Item(0).Attributes["ElementId"].Value);
newEntireRichContent =
objwsRichContent.GetRichTextContent(frmServer.auth enticationToken,
node);
Word.Range currentRange =
Globals.ThisAddIn.Application.Selection.Range;
currentRange.Text = newEntireRichContent;
frmImport.ActiveForm.Visible= false;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
frmImport.ActiveForm.Visible = false;
}
private void treeView1_AfterSelect(object sender,
TreeViewEventArgs e)
{
}
}
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Caversham |
last post by:
Is there any macro / other tool - free or commercial - that can split
long Word docs into multiple XHTML pages?
Any comments on the quality/effectiveness of suitable products also
welcomed.
|
by: Mike MacSween |
last post by:
tblCourses one to many to tblEvents.
A course may have an intro workshop (a type of event), a mid course
workshop, a final exam. Or any combination. Or something different in the
future.
At...
|
by: Andre |
last post by:
Hi
I've a proble that when i run my webservice it now shows the htmltags i've
embedded in my documentation
</td><td>this is a request for a complete
personsinfo.</br>" +
...... etc etc
|
by: bessington |
last post by:
hey all,
i'm having a rather bizarre problem.. the image tag i have declared in
my xhtml is not showing in safari / konqueror but showing just fine in
Firefox, IE, Opera... this is a complete...
|
by: Darsin |
last post by:
What i am doing is to pull the data from a CMS and import it to Word
2007 Beta and i also have to export the data from Word 2007 Beta back
to that CMS. We have with us two Web Services of the CMS....
|
by: Neil |
last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text
feature does not support: a) full text justification; b) programmatic
manipulation.
I was hoping that someone might...
|
by: Stanimir Stamenkov |
last post by:
I've found some contradiction I want to resolve.
<http://www.w3.org/MarkUp/2004/xhtml-faq#mime11states:
I've noted "_disallowed_ text/html" and "_must_ be sent with an
XML-related media...
|
by: Guy Macon |
last post by:
cwdjrxyz wrote:
HTML 5 has solved the above probem. See the following web page:
HTML 5, one vocabulary, two serializations
http://www.w3.org/QA/2008/01/html5-is-html-and-xml.html
|
by: Henry Stock |
last post by:
I can understand what these error messages are telling me, but I guess I am
not sure how to address them all.
The bold tag could be handled in a class attribute, but I need a <br/tag
inside the...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |