tags:

views:

175

answers:

1

Here is an example of the XQuery output that I get:

<clinic>
    <Name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;Healthy Kids Pediatrics</Name>
    <Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;510 W 27th St, Los Angeles, CA 90007</Address>
    <PhoneNumberList>213-555-5845</PhoneNumberList>
    <NumberOfPatientGroups>2</NumberOfPatientGroups>
</clinic>

As you can see, in the <Name> and <Address> tag, there are these strange xmlns:xsi tags being added to it.

The funny thing is if I go to the top of my xml file, and remove:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="vaccination.xsl"?>
<Vaccination xsi:noNamespaceSchemaLocation="vaccination.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;

the phrase

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Then now my XQuery XML output will look like this (which is what I want)

<clinic>
    <Name>Healthy Kids Pediatrics</Name>
    <Address>510 W 27th St, Los Angeles, CA 90007</Address>
    <PhoneNumberList>213-555-5845</PhoneNumberList>
    <NumberOfPatientGroups>2</NumberOfPatientGroups>
</clinic>

BUT, when I view my XML in my browser, it will give an error and display something like:

XML Parsing Error: prefix not bound to a namespace
Location: file:///C:/Users/Pac/Desktop/csci585-hw3/vaccination.xml
Line Number 3, Column 1:<Vaccination xsi:noNamespaceSchemaLocation="vaccination.xsd">
^

Does anyone have an idea of how to remove those xsi tags from my XQuery output without breaking my XML/XSL ?

A: 

Removing the namespace declaration from the top node makes the XML document invalid, as the xsi prefix is used but not declared. This should have caused an error when you try to load the document in a query.

I assume that the Name and Address nodes are copied directly from the source document and the other nodes are constructed.

When copying a node from the source document, the in scope namespaces from the source node are combined with the in scope namespaces in the node that contains the copy. The way these are combined is specified by the copy-namespaces-mode.

In your case you want namespaces to be inherited from the parent node (the node in the query), but you do not want to preserve namespaces in the source document where they are unnecessary.

This can be achieved by adding the following line to the top of the query:

declare copy-namespaces no-preserve, inherit;
Oliver Hallam
Perfect. Works like a charm. Thank you!
ShaChris23