• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

substring query



hi all

i have a string "<?xml version="1.0" encoding="UTF-8"?><node><element>some data</element></node>"

can someone tell me how i get the section <?xml version="1.0" encoding="UTF-8"?> and remove it from the string, so i am left with <node><element>some data</element></node>

many thanks

0
dalecon
Asked:
dalecon
  • 4
  • 3
  • 2
1 Solution
 
StillUnAwareCommented:
s = "<?xml version="1.0" encoding="UTF-8"?><node><element>some data</element></node>";
s = s.substring(0, s.indexOf("<?")) + s.substring(s.stringOf(">?")+2, s.length());

or something similar using regex or even some other technique
0
 
StillUnAwareCommented:
Sorry, I made some typos. It should be:

    String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><node><element>some data</element></node>";
    s = s.substring(0, s.indexOf("<?")) + s.substring(s.indexOf("?>")+2, s.length());
    System.out.println(s);
0
 
phuocnhCommented:
Where you get that string? If you get it from xml document, the following method is good for you
import org.dom4j.*;
 String s="<?xml version=\"1.0\" encoding=\"UTF-8\"?><node><element>some data</element></node>";
  try
  {
    Document doc = DocumentHelper.parseText(s);
    s=doc.getRootElement().asXML();
  }
  catch (DocumentException de)
  {
   de.printStackTrace();  
  }
Phuoc H. Nguyen
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
daleconAuthor Commented:


i get the string using jdom
0
 
phuocnhCommented:
Yeah you can use same as my post to remove the header. So, you needn't remove it.
0
 
daleconAuthor Commented:


what jar is import org.dom4j.*; in, i can't find it


thanks
0
 
phuocnhCommented:
I use dom4j but jdom
0
 
daleconAuthor Commented:
no worries found it
0
 
daleconAuthor Commented:


cool that works
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now