L
lanegroups
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
FormatterTreeWalker 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>123</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>123</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!!
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
FormatterTreeWalker 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>123</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>123</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!!