Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Problem with XPath expression in Word 2007

From: Rainer <wolf.rainer@-----.--->
To: NULL
Date: 10/7/2008 6:56:00 AM
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(wdContentControlText)
    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.SetMapping 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,

Rainer


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent