positioning and inserting xml nodes

B

buzzi

Hi everybody

I've got this little problem that makes me sick!

I have a WordML file (managed through a SmartDoc application) and I
SIMPLY need to programatically insert a new xml element.
I easily move around the xml structure using DOM methods and Xpath
queries... but once I get to the desired Word.XMLNode I'm not able to
insert the new XML element WHERE I really want to.
I need to place it either just BEFORE or just AFTER the closing tag of
the selected element...

E.G.
"<myNode>... ... X</myNode>" --> "<myNode>... ... <newnode/></myNode>"
"<myNode>... ... </myNode>X" --> "<myNode>... ... </myNode><newnode/>"

(The node I want to add is valid according to the associated schema,
etc. etc. my problem is POSITIONING. I couldn't find something similar
to XmlDOM "insertAfter" method...)

Can anyone please help me?

Thanks in advance
Alberto
 
D

docjah

Hi,
If you do something like this:

Set curNode to the one you want to insert after:

wordRange.SetRange(curNode.Range.End + 1, curNode.Range.End + 1)
wordRange.InsertParagraphAfter()
wordRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
wordRange.InsertXML("<Section>Add Title</Section>")

This seems to work.

Dave

Hi everybody

I've got this little problem that makes me sick!

I have a WordML file (managed through a SmartDoc application) and I
SIMPLY need to programatically insert a new xml element.
I easily move around the xml structure using DOM methods and Xpath
queries... but once I get to the desired Word.XMLNode I'm not able to
insert the new XML element WHERE I really want to.
I need to place it either just BEFORE or just AFTER the closing tag of
the selected element...

E.G.
"<myNode>... ... X</myNode>" --> "<myNode>... ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top