Hello,

I have a question about marshalling raw xml segments.

With reference to the example at: 
http://www.castor.org/how-to-unmarshal-raw-xml.html

What I want is the xml fragment 
"<misc>Misc xml to be dealt with later</misc>"
The example gives a result that includes the parent element "xmlnode2"

So with the requirement that the fragment could be any element.
How do I get only the fragment I want.

Furthermore the xml I have to unmarshall is more like the following:

<root xmlns="nsouter">
        <xmlnode attribute="misc xml data">
                <data>Data 1</data>
                <data>Data 2</data>
        </xmlnode>
        <string>Regular String Data</string>
        <xmlnode2>
                <misc xmlns="nsinner">Misc xml to be dealt with later</misc>
        </xmlnode2>
</root>

I need to unmarshall the fragment:
"<misc xmlns="nsinner">Misc xml to be dealt with later</misc>" 
with the right namespace

I have tried to adjust the FieldHandler:

  public Object convertUponSet(final Object value)
  {
    AnyNode result = null;

    final AnyNode node = (AnyNode) value;
    if (node != null)
    {
      result = node.getFirstChild();
      if (result.getNodeType() != AnyNode.ELEMENT)
      {
        result = result.getNextSibling();
      }
    }

    if (result == null || result.getNodeType() != AnyNode.ELEMENT)
    {
      throw new BindingRuntimeException("failed to extract the Message Body xml 
segment");
    }
    return result.toString();
  }
  
But result = node.getFirstChild(); gives me an AnyNode that has the same 
namespace of the parent (nsouter) ?


Greetings,
Huub  

Reply via email to