Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:18:29+00:00 2026-05-26T16:18:29+00:00

I have a string of XML that looks like this: <e1 atr1=3 atr2=asdf> <e1b

  • 0

I have a string of XML that looks like this:

<e1 atr1="3" atr2="asdf">
<e1b atr3="3" atr4="asdf">
    <e1c atr5="3" atr6="asdf"/>
    TestValue1
</e1b>
<e1b atr3="3" atr4="asdf">
    <e1c atr5="3" atr6="asdf"/>
    TestValue2
</e1b>
</e1>

It is different than other XML I have parsed in the past because the e1b elements have values TestValue1 and TestValue2 as well as child elements (e1c).

If an element has both attributes and a value, you have to create a custom converter for xstream to be able to parse it. My attempt at that is below, but because the e1b element has attributes, child elements, AND a value, I’m not sure how to handle it. In my converter, I have left off all references to the e1c child element. What do I need to add to the converter to allow it to handle the e1c element correctly? Right now, e1c values are not getting populated when I do a xstream.fromXML().

public class e1Converter implements Converter {

@SuppressWarnings("rawtypes")
public boolean canConvert(Class clazz) {
    return e1b.class == clazz;
}

public void marshal(Object object, HierarchicalStreamWriter hsw,
        MarshallingContext mc) {
    e1b e = (e1b) object;
    hsw.addAttribute("atr3", e.getAtr3());
    hsw.addAttribute("atr4", e.getAtr4());

    hsw.setValue(e.getE1bValue());
}

public Object unmarshal(HierarchicalStreamReader hsr,
        UnmarshallingContext uc) {

    e1b e = new e1b();
    e.setAtr3(hsr.getAttribute("atr3"));
    e.setAtr4(hsr.getAttribute("atr4"));
    e.setE1bValue(hsr.getValue());

    return e;
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:18:29+00:00Added an answer on May 26, 2026 at 4:18 pm

    According to Jörg on the xstream mailing list:

    Actually you cannot. XStream cannot read mixed-mode XML i.e. XML where
    text and child elements are mixed at the same level. The readers will
    simply act in undefined behavior. This kind of XML does simply not
    fit into the hierarchical stream model of XStream. What’s the value
    of parent here:

    <parent> what <child/>is <child/> the <child/>value <child/>now? </parent
    

    Sorry, Jörg

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML string that looks like this: <Attributes> <ProductAttribute id=1> <ProductAttributeValue> <Value>a</Value>
I have an xml file that looks like this: ... <e1> <e2> <e3>content1.1</e3> <e3>content1.2</e3>
I have converted a table as an xml string that looks something like <NewDataSet>\r\n
I have an XML document that looks like this <Elements> <Element> <DisplayName /> <Type
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
So i have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <gesmes:Envelope
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have an xml formatted document that looks like this: <?xml version=1.0 encoding=windows-1250?> <
I have a XML file, that looks like this inside: <Data> <INFO> .. ...
I have a controller that looks like this for importing xml to my site:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.