INCLUDETEXT with XML file: how to get one single element ?

D

Did

Hi.
I just tried the MS example showing how to get an element from a XML file
but I do not have the expected result.

1. The XML input file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bookstore xmlns="schema.xsd">
<book>
<title>What's New for Office 2003 Developers?</title>
<author>
<first-name>Paul</first-name>
<last-name>Cornell</last-name>
</author>
<price>49.99</price>
</book>
</bookstore>

2. The fields tag:
{ INCLUDETEXT "books_instance.xml" \c xml \n xmlns:ns1='schema.xsd' \x
/ns1:bookstore/ns1:book/ns1:author/ns1:last-name \* MERGEFORMAT }

3. The expected result:
Cornell

4. My result:
What's New for Office 2003 Developers?

Paul
Cornell

49.99

Additional information:
# I am using Word 2003 (MS Office Basic Edition 2003).
# In the MS-example the step by step description to build the INCLUDETEXT
tag is:
1. On the Insert menu, click Field.
2. In the Field names list, select IncludeText.
3. In the Filename or URL box, type the location of the target XML file,
and click OK to include all of the XML data. To include only a portion of
the XML data, continue with the steps 4 through 7.
4. Specify namespace mappings by selecting the Namespace mappings check
box and type the namespace mappings in the accompanying text box.
5. If you want to transform the XML file's data before you include it in
the document, select the XSL transform file check box and type the location
of the target XSL transform file.
6. Check the XPath expression check box and type an XPath expression,
including namespaces if needed.
7. Click OK to include the XML data.
On my version, there is no "Namespace mappings" check/text box, no "XSL
transform file" check/text box and no "XPath expression" check/text box,
therefore I was unable to perform step 4, 5 and 6. I just manually complete
the INCLUDETEXT tag with the relevant data.

Thanks for help.
Did.
 
P

Peter Jamieson

I think the main thing you need to do is double up the forward slashes in
your \x parameter. You may also need to change your single quotes ' to \"
(backslash double-quote), but I do not think so.

i.e. at least change

{ INCLUDETEXT "books_instance.xml" \c xml \n xmlns:ns1='schema.xsd' \x
/ns1:bookstore/ns1:book/ns1:author/ns1:last-name \* MERGEFORMAT }

to

{ INCLUDETEXT "books_instance.xml" \c xml \n xmlns:ns1='schema.xsd' \x
//ns1:bookstore//ns1:book//ns1:author//ns1:last-name \* MERGEFORMAT }
 
C

Cindy M -WordMVP-

Hi Did,
On my version, there is no "Namespace mappings" check/text box, no "XSL
transform file" check/text box and no "XPath expression" check/text box,
therefore I was unable to perform step 4, 5 and 6. I just manually complete
the INCLUDETEXT tag with the relevant data.
FWIW, I *do* see these entries in the Insert/Field box. You don't have a beta
version, do you? What version number (Help/About)?

1. As I recall, you need to assign have the bookstore namespace to a
"variable" and include that *in the tags* in the XML file so that it's clear
they belong to this namespace. IOW
<bookstore xmlns:a="schema.xsd">
<a:last-name>XYZ</a:last-name>

2. Remember, all XML stuff is case-sensitive, so you should check that

3. { INCLUDETEXT "C:\\FullPath\\books_instance.xml" \n
xmlns:ns1='schema.xsd' \x
/ns1:bookstore/ns1:book/ns1:author/ns1:last-name }

Note also that the URN normally would not be anything so generic as a file
named schema.xsd. And you might try including urn in the namespace
declaration:
<bookstore xmlns:a="urn:schema.xsd">

Here's a combination that does work for me

<?xml version="1.0"?>
<x:BOOK xmlns:x="urn:BOOKtest">
<x:TITLE>The Adventures of Huckleberry Finn</x:TITLE>
<x:AUTHOR>Mark Twain</x:AUTHOR>
<x:BINDING>mass market paperback</x:BINDING>
<x:pAGES>298</x:pAGES>
<x:pRICE>$5.49</x:pRICE>
</x:BOOK>

INCLUDETEXT "J:\\Path\\Book.xml" \n xmlns:a='urn:BOOKtest' \x
a:BOOK/a:AUTHOR

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

Did

Hi Cindy.

I think that everything was fine with my case, syntax and all this stuff, by
the way, I have exactly the same kind of result with your own code
(picked-up via cut and paste):
The Adventures of Huckleberry Finn
Mark Twain
mass market paperback
298
$5.49

Therefore, I guess that the problem is with Word (my version) shown below:
Microsoft Office Word 2003 (11.5604.5703)
Part of Microsoft Office Basic Edition 2003.

Because of the "missing" check/text boxes, I also thought it was a
functionality which is not available to me... I already checked that all the
items from my MS Office Basic Edition 2003 have been installed to run from
my hard drive, and it is fine.
Is there any add-in required to use XML sources ?

Did.
 
P

Peter Jamieson

At least some of the XML capability is only available with either Office Pro
2003 or the standalone version of Word 2003. However, I don't know which
bits are missing.

The stuff I posted on another branch of this thread worked here with Office
Pro 2003, Word version 11.5604.5606
 

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