473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Stripping Namespace

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
Nov 12 '05 #1
1 1400
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]
http://blog.tkachenko.com
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
3
by: Steveo | last post by:
I am currently stripping HTML from a string with the following code. (I know it's not the best way to strip HTML but bear with me) re.compile("<.*?>") I wanted to allow all H1 and H2 tags so i...
2
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I...
16
by: John Smith | last post by:
Hi all Why doesn't this seem to work? void stripnl(char *sz) { char *nl; nl = strchr(sz, '\n'); if (nl) {
4
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
4
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
7
by: Edward Elliott | last post by:
I'm looking for the "best" way to strip a large set of chars from a filename string (my definition of best usually means succinct and readable). I only want to allow alphanumeric chars, dashes,...
2
by: delyan.nestorov | last post by:
Hi All, I have the following problem: I read lines from DXF file ( AutoCAD format file ). Then I need to remove white spaces from lines to continue working on data i.e. converting from string...
1
by: Clive Dixon | last post by:
Given an XmlNode with namespace (NamespaceURI has a value), I want to be able to make a clone of it (XmlNode.CloneNode) but without the namespace. How can I strip the namespace from a node?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.