English 中文(简体)
XQuery: weird xsi attribute being inserted into my XQuery output
原标题:
  • 时间:2009-11-22 20:04:57
  •  标签:
  • xquery
  • xsi

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

<clinic>
    <Name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Healthy Kids Pediatrics</Name>
    <Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">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">

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 ?

最佳回答

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;
问题回答

暂无回答




相关问题
XQuery, fn:id and BD eXist

Does "fn:id" function return IDREFS when it is used in a FLOWER xquery with eXists database? I can t get any example... :(

SQL Server xQuery return NULL instead of empty

So in this example I m trying to return a NULL instead of an empty nvarchar for element2 and element3. I can t seem to find an answer to this anywhere, or if it s even possible. I know I can check ....

Does QExo XQuery string-join work?

When I run string-join, I get a weird output like this: <clinic> <Name>Olive Street Pediatrics</Name> <Address>1500 Olive St, Los Angeles, CA 90015</Address> <...

XQuery: how to properly append , in for loop

So I have xml data like this: <PhoneNumber>213-512-7457</PhoneNumber> <PhoneNumber>213-512-7465</PhoneNumber> and with this XQuery: <PhoneNumberList> { for $...

Filter SQL queries on the XML column using XPath/XQuery

I m having a table with one XML column. I d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this ...

热门标签