Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to Have Schema Without a Root Node? 2

Status
Not open for further replies.

BoulderBum

Programmer
Jul 11, 2002
2,179
US
Is it possible to define an XSD such that no root node is defined, just the possibility of a mix of several nodes (such as you'd have for XHTML)?

If so, is there a simple example anyone can provide? I can't seem to Google the answer or get a working example going.
 
Thanks guys!

This is still fuzzy for me, though. The entire XHTML schema is a bit overwhelming for someone so new to schema like me (though the link is useful and I did manage to strip down the XHTML schema to meet my needs).

Also, the .NET example seems like what I'm looking for, but the XmlValidatingReader I used barfed with any sample data that doesn't contain a root element (which was the original source of my confusion).

It turns out that when I was using the XmlValidatingReader, I was setting the XmlNodeType to "Document" which does require a root element. Setting the node type to "Element" cleared up that problem.

Things appear to be working now, though on a side note, do you guys know if there's anything I can do in a schema to enforce self-closing tag vs. empty tags?

In particular, is there a way I can tweak my schema to require <br/> and not <br></br>?
 
>In particular, is there a way I can tweak my schema to require <br/> and not <br></br>?
Not that I know of. But you can get that particular result with a supplementary xsl transformation. This is how.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="@*|node()|comment()|processing-instruction()">
<xsl:if test="count(descendant::*)">
<xsl:copy>
<xsl:apply-templates select="@*|node()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:if>
<xsl:if test="not(count(descendant::*))">
<xsl:if test="normalize-space(.)">
<xsl:copy>
<xsl:apply-templates select="@*|node()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:if>
<xsl:if test="not(normalize-space(.))">
<xsl:element name="{name(.)}" />
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Thanks for the reply.

The issue is that I want to store the schema for an XML field in SQL Server 2005. The schema I have works to restrict to only the elements I want, but it appears that SQL Server doesn't allow text nodes at the root when a schema of elements is defined.

As a workaround, I think I'll just wrap the input in a root <span> element at the application level, though I don't like the extra code involved with that solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top