views:

124

answers:

4

I have designed a xml schema to parse an incoming xml document. The receive location gets xml documents from 2 feeds, one of them has misspelled a node in the document, "Roookie" instead of "Rookie", Is there a way to have my existing xsd parse this document?

A: 

You would need to replace the elements in the document or modify the xsd to work with the new document format.

Mitchel Sellers
A: 

Just modify your schema to accept a choice between 2 nodes (Rookie or Roookie) instead of simply 1 node named Rookie. Both nodes have the same type. Of course, if Roo(o)kie has a complex contents, you'll want to declare a complex type for this contents in order to avoid duplicating the whole structure of the 2 elements.

Serge - appTranslator
I declared another element as "Roookie" in the schema. There is a custom functiod that checks for input from both the nodes and returns the one which has the value, as on of them would be always present in the document ... this will work for me
Nick
This would mean all his code would need to be "polluted" with special handling to support both nodes. I believe it would be better to take care of "normalizing" the input once in a map/xslt, and then simply use the normalized representation everywhere else.
ckarras
+2  A: 

You could probably preprocess the wrong XML file, like with this simple XSL stylesheet:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

<xsl:output method="xml" indent="no"/>

<xsl:template match="Roookie">
        <Rookie>
                <xsl:apply-templates select="@*|node()" />
        </Rookie>
</xsl:template>

<xsl:template match="@*|node()" name="defaultRule">
        <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
</xsl:template>

</xsl:stylesheet>
phihag
I believe the template match for Rookie should actually be the Roookie, to catch the bad elements. Correct?
Mitchel Sellers
A: 

The onyl answer here is to modify the bad message. The xsd is a contract and should be adhered to by submitting systems. If you don't have this kind of control over the submitting systems, I'd suggest making a second schema with a new name and have it accomodate the spelling error. I fyou start altering your contract/xsd for every mistake in a message, you will increase complexity and decrease maintainability.

ChrisLoris