public XhtmlNode addTag(String name) { if (!(nodeType == NodeType.Element || nodeType == NodeType.Document)) throw new Error("Wrong node type. is "+nodeType.toString()); XhtmlNode node = new XhtmlNode(NodeType.Element); node.setName(name); childNodes.add(node); return node; }
public XhtmlNode addTag(int index, String name) { if (!(nodeType == NodeType.Element || nodeType == NodeType.Document)) throw new Error("Wrong node type. is "+nodeType.toString()); XhtmlNode node = new XhtmlNode(NodeType.Element); node.setName(name); childNodes.add(index, node); return node; }
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; }
private XhtmlNode parseFragment() throws IOException, FHIRException { skipWhiteSpace(); if (peekChar() != '<') throw new FHIRException("Unable to Parse HTML - does not start with tag. Found "+peekChar()+descLoc()); readChar(); if (peekChar() == '?') { readToTagEnd(); skipWhiteSpace(); if (peekChar() != '<') throw new FHIRException("Unable to Parse HTML - does not start with tag after processing instruction. Found "+peekChar()+descLoc()); readChar(); } String n = readName().toLowerCase(); readToTagEnd(); XhtmlNode result = new XhtmlNode(NodeType.Element); int colonIndex = n.indexOf(':'); if (colonIndex != -1) { n = n.substring(colonIndex + 1); } result.setName(n); unwindPoint = null; List<XhtmlNode> p = new ArrayList<XhtmlNode>(); parseElementInner(result, p, null, true); return result; }
public XhtmlNode addTag(int index, String name) { if (!(nodeType == NodeType.Element || nodeType == NodeType.Document)) throw new Error("Wrong node type. is "+nodeType.toString()); XhtmlNode node = new XhtmlNode(NodeType.Element); node.setName(name); childNodes.add(index, node); return node; }
public XhtmlNode addTag(String name) { if (!(nodeType == NodeType.Element || nodeType == NodeType.Document)) throw new Error("Wrong node type. is "+nodeType.toString()); XhtmlNode node = new XhtmlNode(NodeType.Element); node.setName(name); childNodes.add(node); return node; }
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; }
private XhtmlNode parseFragment() throws IOException, FHIRException { skipWhiteSpace(); if (peekChar() != '<') throw new FHIRException("Unable to Parse HTML - does not start with tag. Found "+peekChar()+descLoc()); readChar(); if (peekChar() == '?') { readToTagEnd(); skipWhiteSpace(); if (peekChar() != '<') throw new FHIRException("Unable to Parse HTML - does not start with tag after processing instruction. Found "+peekChar()+descLoc()); readChar(); } String n = readName().toLowerCase(); readToTagEnd(); XhtmlNode result = new XhtmlNode(NodeType.Element); int colonIndex = n.indexOf(':'); if (colonIndex != -1) { n = n.substring(colonIndex + 1); } result.setName(n); unwindPoint = null; List<XhtmlNode> p = new ArrayList<XhtmlNode>(); parseElementInner(result, p, null, true); return result; }