Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XML General > MS Office and XML

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-07-2008, 07:27 PM
Rainer
 
Posts: n/a

Default Problem with XPath expression in Word 2007



Hello everybody,

I need to format a long XML file with Word 2007. I try to do this with
the new "custom XML" features in conjunction with content controls.
However, I have a problem using XPath expressions programmatically.
Consider the following XML file called "foo.xml":

<foo title="an attempt">
<ul>
<li>This works fine</li>
<li>Before the inline element <em>Inside the inline element</em> after
the inline element</li>
<li>This also works fine</li>
</ul>
</foo>

I load this file into Word 2007 using a short VBA sub (Alt-F11):

Sub load_custom_xml_part()
ActiveDocument.CustomXMLParts.Add.Load ("c:\foo.xml")
End Sub

The content control for the mapping can also be created
programmatically:

Sub create_content_control()
Dim strTitle As String
strTitle = "My_arbitrary_title"
Dim oCC2 As Word.ContentControl
Set oCC2 =
Application.Selection.ContentControls.Add(wdConten tControlText)
oCC2.Title = strTitle
End Sub

In order to map the content of the first list element into the content
control, I use the XPath expression "/foo/ul/li[1]", which works fine:

Sub bind_nodes()
Dim strXPath As String
strXPath = "/foo/ul/li[1]"
ActiveDocument.ContentControls(1).XMLMapping.SetMa pping strXPath
End Sub

However, I need an XPath expression that returns the second list
element in three "portions" as they have to be formatted with separate
content controls:

- "Before the inline element "
- "Inside the inline element"
- " after the inline element"

The XPath expression "/foo/ul/li[2]/text()[1]" worked perfectly fine
when I tested it with this XPath Demo website:

http://www.futurelab.ch/xmlkurs/xpath.en.html

However, it doesn't seem to work with VBA. The content control doesn't
change its text when I use

strXPath = "/foo/ul/li[2]/text()[1]"

inside of bind_nodes().

Any ideas?

Kind regards,

Reply With Quote
Sponsored Links
Reply


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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 10:17 AM.
Style Developed by Epic Designz