A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Inserting block level xml fragments.



 
 
Thread Tools Display Modes
  #1  
Old June 11th, 2004, 10:14 PM
external usenet poster
 
Posts: n/a
Default Inserting block level xml fragments.

I am trying to insert the following xml fragment into a WordML document programmatically:

ns0:catalog
....
ns0:item
ns0:title wlaceholder="Enter item title."
w
wPr
wStyle w:val="Heading2" /
/wPr
/w
/ns0:title
ns0:description wlaceholder="Enter item description."
w
wPr
wStyle w:val="Normal" /
/wPr
/w
/ns0:description
ns0:item
....

/ns0:catalog


But, i cannot achieve the result no matter what I try.
I am getting errors like Xml node cannot be inserted at current selection, null object reference exceptions, etc.
Title item gets created and than it appears deleted when InsertParagraphAfter() is called(can see it when the revision tracking is on, plus XmlBeforeDelete event fires), which violates the document schema.
Plus, another paragraph gets created between the item and the title nodes.
I am sick and tired of fighting with the paragraphs already.
Did anyone else run into this kind of issues?
Does anyone have a solution or knows how to overcome this?

here is the code that I use:

/// summary

/// Adds new item xml node

/// /summary

internal Word.XMLNode AddItem(Word.XMLNode parentNode, string titlePlaceholderText, string descriptionPlaceholderText)

{

Word.XMLNode itemNode = null;


object start = parentNode.Range.End - 1;

object end = parentNode.Range.End - 1;

object rng = this.ThisDocument.Range(ref start, ref end);


itemNode = parentNode.XMLNodes.Add("title", this.XmlNamespace, ref rng);

if (itemNode==null)

{

throw new ExecutionEngineException("Unable to create item node");

}


itemNode.Range.InsertParagraph();


//TODO: Set paragraph style


rng = itemNode.Range;


Word.XMLNode titleNode = itemNode.XMLNodes.Add("title", this.XmlNamespace, ref rng);

if (titleNode==null)

{

throw new ExecutionEngineException("Unable to create title node");

}


titleNode.PlaceholderText = "Enter title here";


titleNode.Range.InsertParagraphAfter();


//TODO: Set paragraph style

start = titleNode.Range.End;

end = itemNode.Range.End;


rng = this.ThisDocument.Range(ref start, ref end);


Word.XMLNode descriptionNode = itemNode.XMLNodes.Add("description", this.XmlNamespace, ref rng);

if (descriptionNode==null)

{

throw new ExecutionEngineException("Unable to create description node");

}


descriptionNode.PlaceholderText = "Enter title here";

titleNode.Range.Select();

return itemNode;

}





Sincerely,
Ruslan
(nospam)newsgroups(nospam)(at)(nospam)ruslan(nospa m)(dot)ca

  #2  
Old June 12th, 2004, 06:35 PM
Beth Melton
external usenet poster
 
Posts: n/a
Default Inserting block level xml fragments.

If you don't get the answer you are looking for here you might try one of the developer newsgroups since that's where the VBA and XML gurus tend to hang out. :-)

--
Please post all follow-up questions to the newsgroup. Requests for assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/


"anonymous" wrote in message news:xjpyc.1184$0A.9016@localhost...
I am trying to insert the following xml fragment into a WordML document programmatically:

ns0:catalog
...
ns0:item
ns0:title wlaceholder="Enter item title."
w
wPr
wStyle w:val="Heading2" /
/wPr
/w
/ns0:title
ns0:description wlaceholder="Enter item description."
w
wPr
wStyle w:val="Normal" /
/wPr
/w
/ns0:description
ns0:item
...

/ns0:catalog


But, i cannot achieve the result no matter what I try.
I am getting errors like Xml node cannot be inserted at current selection, null object reference exceptions, etc.
Title item gets created and than it appears deleted when InsertParagraphAfter() is called(can see it when the revision tracking is on, plus XmlBeforeDelete event fires), which violates the document schema.
Plus, another paragraph gets created between the item and the title nodes.
I am sick and tired of fighting with the paragraphs already.
Did anyone else run into this kind of issues?
Does anyone have a solution or knows how to overcome this?

here is the code that I use:

/// summary

/// Adds new item xml node

/// /summary

internal Word.XMLNode AddItem(Word.XMLNode parentNode, string titlePlaceholderText, string descriptionPlaceholderText)

{

Word.XMLNode itemNode = null;


object start = parentNode.Range.End - 1;

object end = parentNode.Range.End - 1;

object rng = this.ThisDocument.Range(ref start, ref end);


itemNode = parentNode.XMLNodes.Add("title", this.XmlNamespace, ref rng);

if (itemNode==null)

{

throw new ExecutionEngineException("Unable to create item node");

}


itemNode.Range.InsertParagraph();


//TODO: Set paragraph style


rng = itemNode.Range;


Word.XMLNode titleNode = itemNode.XMLNodes.Add("title", this.XmlNamespace, ref rng);

if (titleNode==null)

{

throw new ExecutionEngineException("Unable to create title node");

}


titleNode.PlaceholderText = "Enter title here";


titleNode.Range.InsertParagraphAfter();


//TODO: Set paragraph style

start = titleNode.Range.End;

end = itemNode.Range.End;


rng = this.ThisDocument.Range(ref start, ref end);


Word.XMLNode descriptionNode = itemNode.XMLNodes.Add("description", this.XmlNamespace, ref rng);

if (descriptionNode==null)

{

throw new ExecutionEngineException("Unable to create description node");

}


descriptionNode.PlaceholderText = "Enter title here";

titleNode.Range.Select();

return itemNode;

}





Sincerely,
Ruslan
(nospam)newsgroups(nospam)(at)(nospam)ruslan(nospa m)(dot)ca

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:27 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.