473,396 Members | 1,918 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.

Print prefix early in Xrces-J

Hello,
I have a DOM which serializes to the following XML. As you see, the
namespace prefixed with "f" is repeated for each object. Is there a way
in Xerces-J to make an unique definition of the prefix in the top-level
element (so as to save room)?

Thanks for answers
Phil

<?xml version="1.0" encoding="UTF-8"?>
<e:test xmlns:e="http://www.example.com/e">
<f:value xmlns:f="http://www.example.com/f">
<f:val>12</f:val>
<f:unit>lux</f:unit>
</f:value>
<f:value xmlns:f="http://www.example.com/f">
<f:val>34.1234</f:val>
<f:unit>ampere</f:unit>
</f:value>
<f:value xmlns:f="http://www.example.com/f">
<f:val>45.0</f:val>
<f:unit>empty_key</f:unit>
</f:value>
</e:test>
Jun 27 '08 #1
4 1393
Philipp wrote:
I have a DOM which serializes to the following XML. As you see, the
namespace prefixed with "f" is repeated for each object. Is there a way
in Xerces-J to make an unique definition of the prefix in the top-level
element (so as to save room)?
It might work to create an xmlns:f attribute on the root element e.g.

documentInstance.getDocumentElement().setAttribute NS("http://www.w3.org/2000/xmlns/",
"xmlns:f", "http://www.example.com/f");

That way the serialization code is hopefully smart enough to avoid
duplicating the namespace declaration on the child elements.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Martin Honnen wrote:
Philipp wrote:
>I have a DOM which serializes to the following XML. As you see, the
namespace prefixed with "f" is repeated for each object. Is there a
way in Xerces-J to make an unique definition of the prefix in the
top-level element (so as to save room)?

It might work to create an xmlns:f attribute on the root element e.g.

documentInstance.getDocumentElement().setAttribute NS("http://www.w3.org/2000/xmlns/",
"xmlns:f", "http://www.example.com/f");

That way the serialization code is hopefully smart enough to avoid
duplicating the namespace declaration on the child elements.
I tried it and unfortunately it's not smart enough :-( It really
duplicates the namespace on each child...
Jun 27 '08 #3
Philipp wrote:
I tried it and unfortunately it's not smart enough :-( It really
duplicates the namespace on each child...
Are you sure those f:value elements do not have an xmlns:f attribute on
their own? If they have then I don't think the serializer will omit them.
So doing
NodeList values =
documentInstance.getElementsByTagName("http://www.example.com/f", "value");
for (int i = 0, l = values.getLength(); i < l; i++)
{
Element value = (Element)values.getItem(i);
value.removeAttributeNS("http://www.w3.org/2000/xmlns/", "f");
}
might be necessary, depending on how your DOM looks.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #4
Martin Honnen wrote:
Philipp wrote:
>I tried it and unfortunately it's not smart enough :-( It really
duplicates the namespace on each child...

Are you sure those f:value elements do not have an xmlns:f attribute on
their own? If they have then I don't think the serializer will omit them.
I typically create them with:
Element node = document.createElementNS("http://www.example.com/f",
"f:value");
root.appendChild(node);

This automatically creates the xmlns:f attributes in the output.
So doing
NodeList values =
documentInstance.getElementsByTagName("http://www.example.com/f", "value");
for (int i = 0, l = values.getLength(); i < l; i++)
{
Element value = (Element)values.getItem(i);
value.removeAttributeNS("http://www.w3.org/2000/xmlns/", "f");
}
might be necessary, depending on how your DOM looks.
Yes, I will try that...

Jun 27 '08 #5

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

Similar topics

2
by: Balaji | last post by:
Hello Eveybody, I have written a method which prints the prefix notation of any expression. here is the method... def PrintPrefix(expr): if expr.__class__==E: print expr.operator,...
23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
0
by: Paul | last post by:
Occasionally my users will try to perform an action and be presented with an exception raised directly from SQL Server, in example: SET @err = 'a user-friendly error condition message'...
6
by: HappyHippy | last post by:
More of a minor niggle than anything but how would I remove the aforementioned space? eg. strName = 'World' print 'Hello', strName, ', how are you today?' comes out as "Hello World , how are...
4
by: BizTalk Benjamin | last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document...
1
by: pipehappy | last post by:
I come this code: Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 Type "help", "copyright", "credits" or "license" for more information. .... def __str__(self): .... ...
9
by: Stef Mientki | last post by:
hello, As part of a procedure I've a number sequences like this: <Python> if Print_Info: print Datafile.readline() else: Datafile.readline() </Python>
5
by: Shraddha | last post by:
Suppose we are having 3 variables...a,b,c And we want to print the permutations of these variables...Such as...abc,acb,bca...all 6 of them... But we are not supposed to do it mannually... I...
10
by: Prisoner at War | last post by:
Hi, your friendly neighborhood n00b here, just wondering why on earth the Py3K folks want to mess with a simple thing like the "print" "command" (is that what it's called, a command?), turning it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.