Update Bibliography XML with "set_Field" method?

M

MIS Dude

Hello fellow programmers!

I'm trying to update the XML of a specific source within the Bibliography in
my Word Document.

e.g. [and to be super explicit...]-->

Microsoft.Office.Interop.Word.DocumentClass.Bibliography.Sources[i +
1].set_Field("THE_ELEMENT_I_WANT_TO_UPDATE","THE_NEW_VALUE_I_WANT_TO_USE");

Has anyone been able to change the InnerText of a single node (or element)
within the Bibliography XML, or is this impossible after adding the
bibliography source XML?

Thank you for your time.

Cheers,
 
P

p0

Hello fellow programmers!

I'm trying to update the XML of a specific source within the Bibliography in
my Word Document.

e.g. [and to be super explicit...]-->

Microsoft.Office.Interop.Word.DocumentClass.Bibliography.Sources[i +
1].set_Field("THE_ELEMENT_I_WANT_TO_UPDATE","THE_NEW_VALUE_I_WANT_TO_USE");

Has anyone been able to change the InnerText of a single node (or element)
within the Bibliography XML, or is this impossible after adding the
bibliography source XML?

Thank you for your time.

Cheers,

According to http://msdn.microsoft.com/en-us/library/bb257219.aspx the
Field property of a Source is read-only. So setting it shouldn't work.
As the same holds for the XML property according to
http://msdn.microsoft.com/en-us/library/bb257223.aspx, I have my
doubts if manipulating it will be possible without deletion and
readding.

The above are just musings, I can not guarantee their correctness.

Yves
 
M

MIS Dude

Hi Yves,

I appreciate the post. I'm looking at the set_Field method that is a member
of the Microsoft.Office.Interop.Word.Source.

If I've been exposed to this method, why would the Source object be
Read-Only? I'm looking at the public interface Source, which is member of
Microsoft.Office.Interop.Word.

Does anyone know how to use this method, (if any), in the context of
updating a specific XML element (or node) in a specific source contained
within the Bibliography.XML of a MS 2007 Word Document?

Your time is much appreciated!

Cheers

p0 said:
Hello fellow programmers!

I'm trying to update the XML of a specific source within the Bibliography in
my Word Document.

e.g. [and to be super explicit...]-->

Microsoft.Office.Interop.Word.DocumentClass.Bibliography.Sources[i +
1].set_Field("THE_ELEMENT_I_WANT_TO_UPDATE","THE_NEW_VALUE_I_WANT_TO_USE");

Has anyone been able to change the InnerText of a single node (or element)
within the Bibliography XML, or is this impossible after adding the
bibliography source XML?

Thank you for your time.

Cheers,

According to http://msdn.microsoft.com/en-us/library/bb257219.aspx the
Field property of a Source is read-only. So setting it shouldn't work.
As the same holds for the XML property according to
http://msdn.microsoft.com/en-us/library/bb257223.aspx, I have my
doubts if manipulating it will be possible without deletion and
readding.

The above are just musings, I can not guarantee their correctness.

Yves
 
P

p0

Hi Yves,

I appreciate the post.  I'm looking at the set_Field method that is a member
of the Microsoft.Office.Interop.Word.Source.

If I've been exposed to this method, why would the Source object be
Read-Only?  I'm looking at the public interface Source, which is memberof
Microsoft.Office.Interop.Word.

I'm just pointing out what the help says.

It's a property. In C# for example you can access a property directly
for both getting and setting: e.g. MyObject.MyProperty = 5 or int x =
MyObject.MyProperty. Internally, this gets translated into two method
calls: MyObject.set_MyProperty(5) and int x = MyObject.get_MyProperty
(). If the setter method would be defined as a null operation, it
wouldn't do anything. So I can see getter or setter operations being
defined in an editor while they do not exist.
Does anyone know how to use this method, (if any), in the context of
updating a specific XML element (or node) in a specific source contained
within the Bibliography.XML of a MS 2007 Word Document?

The following VBA function works.

Public Function TestSomething()

ActiveDocument.Bibliography.Sources.Item(1).Field("Year") = "2008"

End Function

Note that if you would change "Year" to "Tag" it won't work. I guess
that's because the value of tag influences the Cited property. Also
note that if the field is not yet defined, then trying to set it also
fails. I'm guessing their "read-only" statement is just a nice way of
saying: it sometimes is settable, but it is easier for us to say it
isn't rather than having the explain when it is and when it isn't.

Your time is much appreciated!

Cheers

Yves
 
M

MIS Dude

Yves! Your macro worked beautifully...well done! Now would you happen to
know the possible translation into C#?

Thank you again,

Cheers,
 
P

p0

The following seems to work in a VSTO addin (if there is a source with
that index):

Globals.ThisAddIn.Application.ActiveDocument.Bibliography.Sources
[2].set_Field("Year", "test");

But I really would advise against using it because
1)the documentation on Source.Field for the Word Object Model says
fields are read-only;
2)tags can not be changed;
3)new fields can not be added;
4)set_Field is not documented as far as I can tell, its behaviour
might change with any update you install.

Do you really need write access to them? Isn't there some other way
you can handle the problem you are facing? If you work offline, you
could manipulate the Open XML directly while the document is closed.

Yves
 
M

MIS Dude

Thank you again for your help Yves. I've yet to try your last suggestion by
starting a new VSTO project in my solution. I believe another work around
could be me starting a VB.NET proj, then accessing the VBA through that.

Have a good one & thanks again.

Cheers,

MIS Dude.

p0 said:
The following seems to work in a VSTO addin (if there is a source with
that index):

Globals.ThisAddIn.Application.ActiveDocument.Bibliography.Sources
[2].set_Field("Year", "test");

But I really would advise against using it because
1)the documentation on Source.Field for the Word Object Model says
fields are read-only;
2)tags can not be changed;
3)new fields can not be added;
4)set_Field is not documented as far as I can tell, its behaviour
might change with any update you install.

Do you really need write access to them? Isn't there some other way
you can handle the problem you are facing? If you work offline, you
could manipulate the Open XML directly while the document is closed.

Yves
--
http://www.codeplex.com/bibliography

Yves! Your macro worked beautifully...well done! Now would you happen to
know the possible translation into C#?

Thank you again,

Cheers,
 

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