[quoted text, click to view] Barry wrote:
> A buffer containing an xml document with a default namespace is fed to
> an XmlValidatingReader. The reader loads a schema targeting the same
> namespace, and is passed to an XslTransform. Because XslTransform does
> not implement XSLT 2.0, I cannot target the default namespace. The xslt
> is long and complex, prefixing all the xpaths is out of the question.
> The only solution I can come up with is to strip ' xmlns="urn:foo"' from
> the root element of the output of the XmlValidatingReader before it gets
> to the XPathNavigator which feeds it to the XslTransform. What is the
> easiest way to do this?
>
> MemoryStream => XmlTextReader => XmlValidatingReader => How to filter at
> this stage? => XPathDocument => Xsltransform
Well, you can implement custom XmlReader, which delegates all calls to a
parent XmlReader (XmlValidatingReader in your chain), while always
exposes empty string in NamespaceUri property. Something like:
public class NamespaceUnawareXmlReader : XmlReader {
private XmlReader parent;
public NamespaceUnawareXmlReader(XmlReader parent) {
this.parent = parent;
}
//XmlReader overrides
public override string Name { get { return parent.Name; } }
//do the rest this way
...
//No namespaces (should it be null or empty string - don't remember ?)
public override string NamespaceURI { get { return ""; }}
public override string Prefix { get { return ""; }}
}
--
Oleg Tkachenko [XML MVP]