I've been trying to create an XML controller class using StAX. My problem is that I am not getting the full string of an element, instead I get small parts of the string. (note some of the content have been hidden for security reasons, these will be displayed as {content})
  Characters characters = event.asCharacters();  if (!characters.isWhiteSpace()) {      System.out.println(characters.getData());  }      The above code does not return the full string.
What I expect to receive is:{responseType} \([0-9]+\) ACC: [0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+
what I get is the above string in 5 individual parts:{responseType} \([0-9]+\) ACC: [0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+
My code:
  public static ArrayList<SmsCommand> readXML() {      if (init()) {          try {              while (eventReader.hasNext()) {                  XMLEvent event = eventReader.nextEvent();                  switch (event.getEventType()) {                  case XMLStreamConstants.START_ELEMENT:                      StartElement startElement = event.asStartElement();                      String qName = startElement.getName().getLocalPart();                      if (qName.equalsIgnoreCase("command")) {                          Iterator<Attribute> attributes = startElement.getAttributes();                          command = new SmsCommand(attributes.next().getValue());                      }                      break;                  case XMLStreamConstants.CHARACTERS:                      Characters characters = event.asCharacters();                      if (!characters.isWhiteSpace()) {                          command.addResponse(characters.getData());                      }                      break;                  case XMLStreamConstants.END_ELEMENT:                      EndElement endElement = event.asEndElement();                      if (endElement.getName().getLocalPart().equalsIgnoreCase("command")) {                          commands.add(command);                      }                      break;                  }              }          }          catch (XMLStreamException e) {              e.printStackTrace();          }      }      return commands;  }      As well as my xml:
  <?xml version="1.0" ?>  <root>    <command type="{command}">      <response>{responseType} \([0-9]+\) ACC: [0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+</response>    </command>  </root>      
No comments:
Post a Comment