473,663 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add namespaces to elements ?

Hi,

is there an easy way to provide all elements in an xml-document of a namespace-prefix.

Example of source file :
<book>
<title>Alaska </title>
</book>

convert to :

<bk:book xmlns:bk="http://localhost/mybooks">
<bk:title>Alask a</bk:title>
</bk:book>

can this be done using XmlDocument or another class ?
thanks
Chris

*************** *************** *************** *************** **********
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 12 '05 #1
1 1118


cm****@yahoo.co m wrote:

is there an easy way to provide all elements in an xml-document of a namespace-prefix.

Example of source file :
<book>
<title>Alaska </title>
</book>

convert to :

<bk:book xmlns:bk="http://localhost/mybooks">
<bk:title>Alask a</bk:title>
</bk:book>

can this be done using XmlDocument or another class ?


It is certainly possible using DOM programming with XmlDocument, you
need to process all element nodes and recreate them in the right
namespace and replace the nodes as needed.

Another way to solve that task is an XSLT stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:param name="prefix" select="'bk'" />
<xsl:param name="namespace URI" select="'http://localhost/mybooks'" />

<xsl:output method="xml" />

<xsl:template match="*">
<xsl:element name="{$prefix} :{local-name()}"
namespace="{$na mespaceURI}">
<xsl:apply-templates select="@* | node() " />
</xsl:element>
</xsl:template>

<xsl:template match="@* | / | processing-instruction() | comment() |
text()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

which can then be applied using XslTransform.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

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

Similar topics

5
6381
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some reason, though, it just doesn't seem to want to split the prefixes from the rest of the tags when parsing. The minidom documentation at http://docs.python.org/lib/module-xml.dom.minidom.html implies that
8
1966
by: Hugh Sparks | last post by:
When processing an xml document that contains elements such as: <element xmlns="goop"/> ... <element xmlns="gleep"/> I want to create two xsl stylesheet templates: one that matches the elements that contain the namespace declaration for "goop" and one that matches the elements that contain the namespace declaration for "gleep".
5
2237
by: Zombie | last post by:
Hi, Can I have 2 namespaces in the same XML schema? In the schema, I wish to declare elements such that some of them belong to one namespace and others belong to a second namespace. Is this possible? Note that both the namespaces should be in the same schema and same xsd file. Could somebody provide a small snippet on how to do this? Thanks for your time.
3
1331
by: tysontate | last post by:
I've been charged with updating old schemas for various files that have never actually been validated against each other. I've got the schema itself in good form at this point - I'm positive that they're pretty clean. My only remaining problem is namespaces. The XML files, which I can't modify, use no namespaces at all. They contain elements from as many as four different files. Example: "CargoList" in CargoList.xsd contains a sequence...
11
4327
by: David Thielen | last post by:
Hi; Once I have loaded an xml file into a DOM, is there any way to then get any namespace declarations that were in the xml file? Or are those just discarded as the DOM is populated? And if you can't get it from the DOM, any other way to get the namespace(s)? I'm assuming doing a SAX read which returns each element including NameSpaces and pull it form that (and build up the DOM at the same time)?
3
4027
by: _DD | last post by:
I believe Balena's Best Practices book suggests grouping quite a few classes into each namespace. I don't remember a number, but this has me curious about how other programmers handle this. If classes are obviously related, then I use the same namespace. Problem is that this doesn't seem to happen often. I could understand Balena's numbers in the context of a specific library, but in the scope of a large program, many corners are...
16
3515
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument and then query for the root element, the result is always null (1). However if I strip the root element of all attributes generated by XmlSpy, then there is no problem to find the root element with .NET XML classes (2). (1) The XML for which...
4
1795
by: VK | last post by:
Can well-formed but non-validated XHTML have extra namespaces? Say <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head>
0
2408
by: davsmith_shop | last post by:
Hopefully I can ask this question without regaling you kind people in too many gory details. Here's what I'm trying to do: - I have a local XML file with a .GPX extension which I downloaded from www.geocaching.com. - The file contains a bunch of elements called <WPT> - Within the WPT elements are a number of other elements <time>, <sym>, <groundspeak:name>... - The non-qualified elements come from a schema/namespace at...
4
1843
by: nallen05 | last post by:
Is there a standardized recommendation for combining names and namespaces into a single URI? I found a post on the Stylus Studio forum asking the same question, the response was "use James Clark's {http://www.namespace.com}name notation". The post is 7 years old and I'm wondering if anything has changed... thanks
0
8436
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8858
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8771
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8634
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.