473,396 Members | 2,129 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,396 software developers and data experts.

roundtripping and xmlns attributes

I am endeavouring to use .NET v2.0 XML facilities to "roundtrip" reading and
writing XML documents - i.e. to end up with _exactly_ what I started with,
but I can't seem to figure out how to get an XMLReader to report "xmlns"
attributes. It seems to report an

"xmlns='MyDefaultURI'"

with incorrect data, and doesn't appear to report

"xmlns:myprefix="MyPrefixURI"

prefix declarations at all. Yes, I know that it correctly processes and
resolves namespaces and prefixes etc, but I want to be able to accurately
report the attribute occurences themselves. Is this possible?

This functionality is easily achieved using Expat btw.

thanks in advance,

gary
Sep 23 '06 #1
3 1863
Whoops, I probably should have mentioned that the "report"ing I was referring
to was the result of calls to "MoveToNextAttribute" on the XMLReader object.

cheers,

gary

"Gary Stephenson" wrote:
I am endeavouring to use .NET v2.0 XML facilities to "roundtrip" reading and
writing XML documents - i.e. to end up with _exactly_ what I started with,
but I can't seem to figure out how to get an XMLReader to report "xmlns"
attributes. It seems to report an

"xmlns='MyDefaultURI'"

with incorrect data, and doesn't appear to report

"xmlns:myprefix="MyPrefixURI"

prefix declarations at all. Yes, I know that it correctly processes and
resolves namespaces and prefixes etc, but I want to be able to accurately
report the attribute occurences themselves. Is this possible?

This functionality is easily achieved using Expat btw.

thanks in advance,

gary
Sep 23 '06 #2


Gary Stephenson wrote:
Whoops, I probably should have mentioned that the "report"ing I was referring
to was the result of calls to "MoveToNextAttribute" on the XMLReader object.

Sorry, I can't reproduce that problem, e.g. file.xml is

<?xml version="1.0" encoding="UTF-8"?>
<gods xmlns="http://example.com/2006/gods"
xmlns:xhtml="http://www.w3.org/1999/xhtml"/>

and a simple C# program snippet is

using (XmlReader xmlReader = XmlReader.Create(@"file.xml")) {
while (xmlReader.Read()) {
if (xmlReader.NodeType == XmlNodeType.Element) {
Console.WriteLine(
"Found element with local name: {0}, namespace URI: {1}.",
xmlReader.LocalName, xmlReader.NamespaceURI);
while (xmlReader.MoveToNextAttribute()) {
Console.WriteLine(
"Found attribute with prefix: {0}, local name: {1}, namespace URI: {2}",
xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
}
Console.WriteLine();
}
}
}

output is

Found element with local name: gods, namespace URI:
http://example.com/2006/gods.
Found attribute with prefix: , local name: xmlns, namespace URI:
http://www.w3.org/2000/xmlns/
Found attribute with prefix: xmlns, local name: xhtml, namespace URI:
http://www.w3.org/2000/xmlns/

so both the default namespace declaration and the other namespace
declaration are reported as attributes. Such attributes are by
definition in the namespace with URI http://www.w3.org/2000/xmlns/, so
that is also correct.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 23 '06 #3
Thanks Martin,

You are correct, of course. I should definitely have tried to post an
example demonstrating my "problem". Presumably this would have prevented my
initial post
as the problem was, of course, a dumb-assed coding error

Apologies to all for wasting valuable bandwidth,

gary

"Martin Honnen" wrote:
>

Gary Stephenson wrote:
Whoops, I probably should have mentioned that the "report"ing I was referring
to was the result of calls to "MoveToNextAttribute" on the XMLReader object.


Sorry, I can't reproduce that problem, e.g. file.xml is

<?xml version="1.0" encoding="UTF-8"?>
<gods xmlns="http://example.com/2006/gods"
xmlns:xhtml="http://www.w3.org/1999/xhtml"/>

and a simple C# program snippet is

using (XmlReader xmlReader = XmlReader.Create(@"file.xml")) {
while (xmlReader.Read()) {
if (xmlReader.NodeType == XmlNodeType.Element) {
Console.WriteLine(
"Found element with local name: {0}, namespace URI: {1}.",
xmlReader.LocalName, xmlReader.NamespaceURI);
while (xmlReader.MoveToNextAttribute()) {
Console.WriteLine(
"Found attribute with prefix: {0}, local name: {1}, namespace URI: {2}",
xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
}
Console.WriteLine();
}
}
}

output is

Found element with local name: gods, namespace URI:
http://example.com/2006/gods.
Found attribute with prefix: , local name: xmlns, namespace URI:
http://www.w3.org/2000/xmlns/
Found attribute with prefix: xmlns, local name: xhtml, namespace URI:
http://www.w3.org/2000/xmlns/

so both the default namespace declaration and the other namespace
declaration are reported as attributes. Such attributes are by
definition in the namespace with URI http://www.w3.org/2000/xmlns/, so
that is also correct.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 23 '06 #4

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

Similar topics

1
by: Chris Bedford | last post by:
Hi: this question has been driving me crazy. would be grateful for any help. I am writing a version of the identity transformation to filter some documents (they happen to be wsdl docs)....
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
8
by: Bob Smith | last post by:
hi all, I pretty new to xml, what does xmlns mean? like in: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"...
1
by: Jack Colletta | last post by:
Hello, If I have a xml document with a rootlevel <workOrderReleased xmlns="http://www.qad.com/qdoc" xmlns:enc="http://www.w3.org/2002/12/soap-encoding"...
0
by: jts2077 | last post by:
I am trying to create a large nested XML object using E4X methods. The problem is the, the XML I am trying to create can only have xmlns set at the top 2 element levels. Such as: <store ...
2
by: aglaforge | last post by:
I'm attempting to write a quick piece of Javascript code that will validate if the end user of the javascript has the necessary VML attributes set in their HTML. The problem in IE is that...
3
by: =?Utf-8?B?R3JlZw==?= | last post by:
If I have an XmlDocument with a deep hierarchy of nodes, with a documentElement having an attribute xmlns="http://someurl.com" and all children inheriting that namespace (but not having the xmlns...
11
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to add the following attributes (xmlns:xsi and xsi:type) to a node (Grantee) like the following: <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">...
4
by: senglory | last post by:
XML: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.