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 4071
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |