/** @param tag */ private String makeElementNameFromHexadecimalGroupElementValues(AttributeTag tag) { StringBuffer str = new StringBuffer(); str.append("HEX"); // XML element names not allowed to start with a number String groupString = Integer.toHexString(tag.getGroup()); for (int i = groupString.length(); i < 4; ++i) str.append("0"); str.append(groupString); String elementString = Integer.toHexString(tag.getElement()); for (int i = elementString.length(); i < 4; ++i) str.append("0"); str.append(elementString); return str.toString(); }
/** * @param list * @param document * @param parent */ void addAttributesFromListToNode(AttributeList list, Document document, Node parent) { DicomDictionary dictionary = list.getDictionary(); Iterator i = list.values().iterator(); while (i.hasNext()) { Attribute attribute = (Attribute) i.next(); AttributeTag tag = attribute.getTag(); String elementName = dictionary.getNameFromTag(tag); if (elementName == null) { elementName = makeElementNameFromHexadecimalGroupElementValues(tag); } Node node = document.createElement(elementName); parent.appendChild(node); { Attr attr = document.createAttribute("group"); attr.setValue(HexDump.shortToPaddedHexString(tag.getGroup())); node.getAttributes().setNamedItem(attr); } { Attr attr = document.createAttribute("element"); attr.setValue(HexDump.shortToPaddedHexString(tag.getElement())); node.getAttributes().setNamedItem(attr); } { Attr attr = document.createAttribute("vr"); attr.setValue(ValueRepresentation.getAsString(attribute.getVR())); node.getAttributes().setNamedItem(attr); } if (attribute instanceof SequenceAttribute) { int count = 0; Iterator si = ((SequenceAttribute) attribute).iterator(); while (si.hasNext()) { SequenceItem item = (SequenceItem) si.next(); Node itemNode = document.createElement("Item"); Attr numberAttr = document.createAttribute("number"); numberAttr.setValue(Integer.toString(++count)); itemNode.getAttributes().setNamedItem(numberAttr); node.appendChild(itemNode); addAttributesFromListToNode(item.getAttributeList(), document, itemNode); } } else { // Attr attr = document.createAttribute("value"); // attr.setValue(attribute.getDelimitedStringValuesOrEmptyString()); // node.getAttributes().setNamedItem(attr); // node.appendChild(document.createTextNode(attribute.getDelimitedStringValuesOrEmptyString())); String values[] = null; try { values = attribute.getStringValues(); } catch (DicomException e) { // e.printStackTrace(System.err); } if (values != null) { for (int j = 0; j < values.length; ++j) { Node valueNode = document.createElement("value"); Attr numberAttr = document.createAttribute("number"); numberAttr.setValue(Integer.toString(j + 1)); valueNode.getAttributes().setNamedItem(numberAttr); valueNode.appendChild(document.createTextNode(values[j])); node.appendChild(valueNode); } } } } }