• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A tag "#document-fragment" is being added while converting object to XML

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

My application uses DOM to convert from java object to XML. While doing this, it is adding a tag by name <#document-fragment> at the start and a correspoding closing tag.
The actual information is contained within the above mentioned tag.

There is no hard coding in the source files. This gets appended automatically. Do NOT know how.

I would like to know if anyone had faced such issue and how was it resolved.

Thanking in advance,
- Jay.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're probably using the getNodeName() or getNodeValue() methods in some odd way. Could you post the piece of code that does the conversion?
 
Jayathirtha Katti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Find below pasted the INCORRECT xml file

<?xml version = '1.0'?>
<#document-fragment><JavaBean CLASS="iom.decomp.data.task.EFMSPMTaskData"><Prope
rties><Property NAME="asr"><JavaBean CLASS="java.util.Vector"><Properties/></Jav
aBean></Property><Property NAME="asrSize">0</Property><Property NAME="eventSched
Date">01/26/2005</Property><Property NAME="eventType">CTP8</Property><Property N
AME="orderNumber">040203509</Property><Property NAME="sdiSize">0</Property><Prop
erty NAME="shopCartNumber">ISR04122029620</Property></Properties></JavaBean>
</#document-fragment>

and the code is as below,

public static DocumentFragment getAsDOM(Document doc, ArrayList arrayList) throws IntrospectionException, InstantiationException,
IllegalAccessException {

// Create the fragment we'll return
DocumentFragment dfResult = null;

// Analyze the ArrayList
Class classOfArrayList = arrayList.getClass();

if (dfResult == null) {
dfResult = doc.createDocumentFragment();
//BeanInfo bi = Introspector.getBeanInfo(classOfBean);
//PropertyDescriptor[] pds = bi.getPropertyDescriptors();

// Add an Element indicating that this is a JavaBean.
// The element has a single attribute, which is that Element's class.
Element eBean = doc.createElement("JavaBean");
dfResult.appendChild(eBean);
eBean.setAttribute("CLASS", classOfArrayList.getName());
Element eProperties = doc.createElement("Properties");
eBean.appendChild(eProperties);

if(arrayList == null || arrayList.size()<1){
return dfResult;
}

for(int k =0; k < arrayList.size(); k++){
Object bean = arrayList.get(k);
DocumentFragment dfragment = XMLBeanWriter.getAsDOM(doc, bean);
if(dfragment != null){
Element eProperty = doc.createElement("Property");
eProperties.appendChild(eProperty);

// Create NAME attribute, add it to Property element,
// and set it to name of property
eProperty.setAttribute("NAME", "ArrayListElement");

// Append the DocumentFragment to the Property element
eProperty.appendChild(dfragment);
}
}

}
return dfResult;
}



The correct xml file is as given below,

--------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<JavaBean CLASS="iom.decomp.data.task.EFMSPMTaskData"><Properties><Property NAME
="asr"><JavaBean CLASS="java.util.Vector"><Properties/></JavaBean></Property><Pr
operty NAME="asrSize">0</Property><Property NAME="eventSchedDate">10/25/2004</Pr
operty><Property NAME="eventType">REJ</Property><Property NAME="orderNumber">040
202443</Property><Property NAME="orderStatus">Rejected</Property><Property NAME=
"sdiSize">0</Property><Property NAME="serviceRequestNumber">040202443</Property>
<Property NAME="shopCartNumber">ISR04102227829</Property></Properties>
</JavaBean>


The tag <#document-fragment> shouldn't have got appended at all.

Please help,

Thanks for your time,
-Jay.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is apparently that you can't print a DocumentFragment node the same way as you can print a Document node. Is there any particular reason why you couldn't just create a new Document (instead of using DocumentFragments)?

Another option could be to "convert" the DocumentFragment into a regular Document before printing, i.e. something like this:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic