private XhtmlNode parseNode(Element node, String defaultNS) throws FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(node.getLocalName()); defaultNS = checkNS(res, node, defaultNS); for (int i = 0; i < node.getAttributes().getLength(); i++) { Attr attr = (Attr) node.getAttributes().item(i); if (attributeIsOk(res.getName(), attr.getName(), attr.getValue()) && !attr.getLocalName().startsWith("xmlns")) res.getAttributes().put(attr.getName(), attr.getValue()); } Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { res.addText(child.getTextContent()); } else if (child.getNodeType() == Node.COMMENT_NODE) { res.addComment(child.getTextContent()); } else if (child.getNodeType() == Node.ELEMENT_NODE) { if (elementIsOk(child.getLocalName())) res.getChildNodes().add(parseNode((Element) child, defaultNS)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(child.getNodeType())+descLoc()); child = child.getNextSibling(); } return res; }
private XhtmlNode parseNode(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(xpp.getName()); for (int i = 0; i < xpp.getAttributeCount(); i++) { if (attributeIsOk(xpp.getName(), xpp.getAttributeName(i), xpp.getAttributeValue(i))) res.getAttributes().put(xpp.getAttributeName(i), xpp.getAttributeValue(i)); } int eventType = xpp.next(); while (eventType != XmlPullParser.END_TAG) { if (eventType == XmlPullParser.TEXT) { res.addText(xpp.getText()); xpp.next(); } else if (eventType == XmlPullParser.COMMENT) { res.addComment(xpp.getText()); xpp.next(); } else if (eventType == XmlPullParser.START_TAG) { if (elementIsOk(xpp.getName())) res.getChildNodes().add(parseNode(xpp)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(eventType)+descLoc()); eventType = xpp.getEventType(); } xpp.next(); return res; }
throw new Error("Not handled yet"); case Node.COMMENT_NODE: xn.addComment(n.getTextContent()); return; case Node.TEXT_NODE:
if (sc.startsWith("DOCTYPE")) throw new FHIRFormatError("Malformed XHTML: Found a DocType declaration, and these are not allowed (XXE security vulnerability protection)"); node.addComment(sc).setLocation(markLocation()); } else if (peekChar() == '?') node.addComment(readToTagEnd()).setLocation(markLocation()); else if (peekChar() == '/') { readChar();
private void skipWhiteSpaceAndComments(XhtmlNode focus) throws IOException, FHIRFormatError { while (Character.isWhitespace(peekChar()) || (peekChar() == 0xfeff)) readChar(); if (peekChar() == '<') { char ch = readChar(); if (peekChar() == '!') { readChar(); if (peekChar() == '-') { readChar(); if (peekChar() == '-') { readChar(); if (peekChar() == ' ') readChar(); focus.addComment(readToCommentEnd()); } else throw new FHIRFormatError("unrecognised element type <!"+peekChar()+descLoc()); } else focus.addDocType(readToDocTypeEnd()); skipWhiteSpaceAndComments(focus); } else if (peekChar() == '?') { String r = readToTagEnd(); focus.addInstruction(r.substring(1, r.length()-1)); skipWhiteSpaceAndComments(focus); } else pushChar(ch); } }
private XhtmlNode parseNode(Element node, String defaultNS) throws FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(node.getLocalName()); defaultNS = checkNS(res, node, defaultNS); for (int i = 0; i < node.getAttributes().getLength(); i++) { Attr attr = (Attr) node.getAttributes().item(i); if (attributeIsOk(res.getName(), attr.getName(), attr.getValue()) && !attr.getLocalName().startsWith("xmlns")) res.getAttributes().put(attr.getName(), attr.getValue()); } Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { res.addText(child.getTextContent()); } else if (child.getNodeType() == Node.COMMENT_NODE) { res.addComment(child.getTextContent()); } else if (child.getNodeType() == Node.ELEMENT_NODE) { if (elementIsOk(child.getLocalName())) res.getChildNodes().add(parseNode((Element) child, defaultNS)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(child.getNodeType())+descLoc()); child = child.getNextSibling(); } return res; }
throw new Error("Not handled yet"); case Node.COMMENT_NODE: xn.addComment(n.getTextContent()); return; case Node.TEXT_NODE:
private XhtmlNode parseNode(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(xpp.getName()); for (int i = 0; i < xpp.getAttributeCount(); i++) { if (attributeIsOk(xpp.getName(), xpp.getAttributeName(i), xpp.getAttributeValue(i))) res.getAttributes().put(xpp.getAttributeName(i), xpp.getAttributeValue(i)); } int eventType = xpp.next(); while (eventType != XmlPullParser.END_TAG) { if (eventType == XmlPullParser.TEXT) { res.addText(xpp.getText()); xpp.next(); } else if (eventType == XmlPullParser.COMMENT) { res.addComment(xpp.getText()); xpp.next(); } else if (eventType == XmlPullParser.START_TAG) { if (elementIsOk(xpp.getName())) res.getChildNodes().add(parseNode(xpp)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(eventType)+descLoc()); eventType = xpp.getEventType(); } xpp.next(); return res; }
if (sc.startsWith("DOCTYPE")) throw new FHIRFormatError("Malformed XHTML: Found a DocType declaration, and these are not allowed (XXE security vulnerability protection)"); node.addComment(sc).setLocation(markLocation()); } else if (peekChar() == '?') node.addComment(readToTagEnd()).setLocation(markLocation()); else if (peekChar() == '/') { readChar();
private void skipWhiteSpaceAndComments(XhtmlNode focus) throws IOException, FHIRFormatError { while (Character.isWhitespace(peekChar()) || (peekChar() == 0xfeff)) readChar(); if (peekChar() == '<') { char ch = readChar(); if (peekChar() == '!') { readChar(); if (peekChar() == '-') { readChar(); if (peekChar() == '-') { readChar(); if (peekChar() == ' ') readChar(); focus.addComment(readToCommentEnd()); } else throw new FHIRFormatError("unrecognised element type <!"+peekChar()+descLoc()); } else focus.addDocType(readToDocTypeEnd()); skipWhiteSpaceAndComments(focus); } else if (peekChar() == '?') { String r = readToTagEnd(); focus.addInstruction(r.substring(1, r.length()-1)); skipWhiteSpaceAndComments(focus); } else pushChar(ch); } }