View Single Post
 
Old 06-14-2017, 12:53 AM
slaycock slaycock is offline Windows 7 64bit Office 2013
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

Quote:
it is if your XML uses a names space then to access the nodes you must reference the namespace prefix. If you don't name it something then Word automatically uses the default namespace prefix ns0.
This is the bit that is confusing because it is not made clear that Word automatically adds a prefix if you define a default namespace. My understanding of XML (whilst limited) suggests that if you define a default namespace (which is what I'm doing), then prefixes are not required.

https://www.w3schools.com/xml/xml_namespaces.asp

Look under default namespaces.

Quote:
Default Namespaces
Defining a default namespace for an element saves us from using prefixes in all the child elements. It has the following syntax:

xmlns="namespaceURI"
This XML carries HTML table information:

<table xmlns="http://www.w3.org/TR/html4/">
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a piece of furniture:

<table xmlns="https://www.w3schools.com/furniture">
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
Once I had the insight that Word was not behaving in line with the reading I'd been doing progress was rapid.

However, even then Word did not appear to play fair. This is the XML output from the test suite above.

Code:
<?xml version="1.0"?>

<arcRoot xmlns="MyUserNS">
	<arcProp ns0:ID="myProp1" xmlns:ns0="MyUserNS">
		<Checked>False</Checked>
		<Enabled>True</Enabled>
		<Value>True</Value>
	</arcProp>
	<arcProp ns0:ID="myProp6" xmlns:ns0="MyUserNS">
		<Visibility>True</Visibility>
		<Checked>False</Checked>
		<Enabled>True</Enabled>
	</arcProp>
	<arcProp ns0:ID="myProp7" xmlns:ns0="MyUserNS">
		<Value>True</Value>
		<Visibility>True</Visibility>
		<Checked>False</Checked>
		<Enabled>True</Enabled>
	</arcProp>
	<arcProp ns0:ID="myProp8" xmlns:ns0="MyUserNS">
		<Visibility>True</Visibility>
		<Checked>False</Checked>
		<Enabled>True</Enabled>
		<Value>True</Value>
	</arcProp>
-	<arcProp ns0:ID="myProp9" xmlns:ns0="MyUserNS">
		<Visibility>True</Visibility>
		<Checked>False</Checked>
		<Enabled>True</Enabled>
		<Value>True</Value>
	</arcProp>
</arcRoot>
As you can see the elements of each property do not use a prefix. However in my code it *WAS* necessary to add a prefix in the VBA code to access the elements (this is in line with the prefix examples fiven earlier in the W3 reference).

I'm happy to accept that my understanding of CustomXMLParts and XML is insufficient which is why I think I'm seeing discontinuities but the evidence to date suggests not.
Reply With Quote