473,804 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pull the namespaces to the serailized XML Fragment using Xalan-C++ API

Dear experts,
I'm trying to do the following using Xalan-C++ API
1. parse an XML document
2. evaluate an XML path
3. serialize the selected XML subtree
4. The new serialized XML fragment should have the correct namespace
declared, based on their declaration from the original XML document.

Task 1-3 are done and I'm using the traverseSubtree method from
FormatterTreeWa lker class to serialize the subtree. However, the
namespace declaration is not put in the new root element by the
traverseSubtree method.
For example,
<doc xmlns:ns1="http ://www.one.com"
xmlns:ns2="http ://www.two.com"
xmlns:ns3="http ://www.three.com"
xmlns="http://www.default.com ">
<ns1:element1 >
<ns2:element2 >
<ns3:element3>1 23</ns3:element3>
</ns2:element2>
</ns1:element1>
</doc>
After evaluating xpath
"'/default:doc/ns1:element1/ns2:element2/ns3:element3"
I can get the serialized fragment as
<ns3:element3>1 23</ns3:element3>

I want to get something below
<ns3:element3 xmlns:ns3="http ://www.three.com"
xmlns="http://www.default.com ">123</ns3:element3>

or

<ns3:element3 xmlns:ns1="http ://www.one.com"
xmlns:ns2="http ://www.two.com"
xmlns:ns3="http ://www.three.com"
xmlns="http://www.default.com ">123</ns3:element3>

I think I can travese the tree again to collect the namespace URIs and
prefixes and generate the string in the root, but that's not effecient.

Are there existing Xalan C++ APIs that can handle this already?
For example, are there Xalan C++ APIs that I can retrieve the related
namespace URIs and prefixes based on the context?

Thanks a lot in advance!!

Oct 31 '06 #1
2 1621
Namespace declarations either have to be copied across explicitly, or
you have to use a serializer that perfoms namespace fixup, or both.

Xalan's stylesheet code does the former when "namespace nodes" are
copied, and its serializer does the latter when necessary.

If you're wrapping different code around the XPath calls, it's your
responsibility to make sure the right things happen. Borrowing Xalan's
serializer might be the simplest solution.
Oct 31 '06 #2
Lan wrote:
What I miss is the part copying "namespace nodes". Can you elaborate
more on the stylesheet code that copy the "namespaces nodes"?
Namespace Nodes are an XSLT/XPath concept. Basically, they're the
declarations in scope at a given node. The normal
copy-a-node-from-source-to-result mechanisms in XSLT (xsl:copy)
conceptually copies these along with the nodes, helping to ensure not
only that all namespaces used in node names are properly defined, but
that those in text content (for example, in XPaths that are part of the
content being processed) have their necessary info.

See the XPath spec's description of the namespace:: axis, and XSLT's
description of how namespace nodes are handled.

If you're hand-coding the copy process, it's up to you to either do this
sort of copying -- determine which declarations are in scope and
explicitly declare them in the output document -- or to have your
serializer regenerate them when you discover that a namespaced node has
a prefix that isn't already declared with that value at this point in
the document.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 1 '06 #3

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

Similar topics

1
3424
by: Dino Morelli | last post by:
Looking for someone familiar with Xalan-j.. I'm having problems isolating a node in a Document with Xalan-j's XPathAPI class when that element is in a namespace. using: Xalan-j v2.5.1 JDK v1.4.2-b28 Given an XML document that looks like this:
0
1947
by: Frank | last post by:
Hey all, I can't seem to get javascript running in my XSL document. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xalan" xmlns:my-ext="ext1" extension-element-prefixes="my-ext"> <!--The component and its script are in the xalan namespace and define the
1
2310
by: Fisch von Gestern | last post by:
I have tried to run the extension function/element examples provided with the Xalan-J download. I believe that my classpath is correct, and that my versions are up-to-date. However, I can't get past the following error. Any help, please? =========================================================================== C:\xalan>test C:\xalan>REM @echo off
8
1971
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".
7
2147
by: Ganesh Gella | last post by:
Hi All, I am planning to use Xalan to transform XML data by applying xls stylesheets. Here tricky part is, Xalan provides several C++ APIs, which are very much useful if our requirement is just inputting a file and getting a file. Or giving a xerces dom and get a new xerces dom. I would like to know whether any of you tried with their own custom
1
1239
by: gimme_this_gimme_that | last post by:
I have the following xml file and need some tips on xpath queries to fetch the data. I think I'm not handling namespaces correctly. Here is xml file : <?xml version="1.0" encoding="UTF-8"?>
3
1845
by: Avalon1178 | last post by:
Hi, I recently downloaded the xalan-c source code in http://mirrors.ccs.neu.edu/Apache/dist/xml/xalan-c I followed the instructions from the apache site on how to build it (I already have xerces downloaded and compiled), however, I'm getting quite a few compile errors. I downloaded and compiled xerces 2.6.0 and I downloaded xalan 1.9.0.
0
1648
by: marfi95 | last post by:
I am creating a fragment for my xml and trying to insert it into my xmldocument. however, some of the child elements in the fragment need to have a namespace prefix, yet when I assign this to the innerxml property, I get an error saying that the prefix is not a namespace (or something similar). I've tried using the namespacemanager, adding this prefix as a namespace. I finally had to resort to creating it with the
3
2348
by: =?iso-8859-1?q?Eduardo_Y=E1=F1ez_Parareda?= | last post by:
Hello, I have to use xalan to transform some XML using XSL, but I have some problems within the XSLs, and Xalan doesn't give very good error messages. Is there any way to put Xalan on debug or trace mode or something else?, it's almost impossible to find the problems with those messages. i.e.: This is /xsl/template/list.xsl
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
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...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
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
7638
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
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
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.