nu.xom.Attribute Java Examples
The following examples show how to use
nu.xom.Attribute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XOMTreeBuilder.java From caja with Apache License 2.0 | 6 votes |
@Override protected void addAttributesToElement(Element element, HtmlAttributes attributes) throws SAXException { try { for (int i = 0; i < attributes.getLength(); i++) { String localName = attributes.getLocalName(i); String uri = attributes.getURI(i); if (element.getAttribute(localName, uri) == null) { element.addAttribute(nodeFactory.makeAttribute(localName, uri, attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } } } catch (XMLException e) { fatal(e); } }
Example #2
Source File: XOMTreeBuilder.java From caja with Apache License 2.0 | 6 votes |
@Override protected Element createElement(String ns, String name, HtmlAttributes attributes) throws SAXException { try { Element rv = nodeFactory.makeElement(name, ns); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalName(i), attributes.getURI(i), attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
Example #3
Source File: XOMTreeBuilder.java From caja with Apache License 2.0 | 6 votes |
@Override protected Element createHtmlElementSetAsRoot(HtmlAttributes attributes) throws SAXException { try { Element rv = nodeFactory.makeElement("html", "http://www.w3.org/1999/xhtml"); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalName(i), attributes.getURI(i), attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } document.setRootElement(rv); return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
Example #4
Source File: XOMTreeBuilder.java From caja with Apache License 2.0 | 6 votes |
@Override protected Element shallowClone(Element element) throws SAXException { try { Element rv = nodeFactory.makeElement(element.getLocalName(), element.getNamespaceURI()); for (int i = 0; i < element.getAttributeCount(); i++) { Attribute attribute = element.getAttribute(i); rv.addAttribute(nodeFactory.makeAttribute( attribute.getLocalName(), attribute.getNamespaceURI(), attribute.getValue(), attribute.getType())); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
Example #5
Source File: XOMTreeBuilder.java From caja with Apache License 2.0 | 6 votes |
/** * @see nu.validator.htmlparser.impl.TreeBuilder#createElement(String, * java.lang.String, org.xml.sax.Attributes, java.lang.Object) */ @Override protected Element createElement(String ns, String name, HtmlAttributes attributes, Element form) throws SAXException { try { Element rv = nodeFactory.makeElement(name, ns, form); for (int i = 0; i < attributes.getLength(); i++) { rv.addAttribute(nodeFactory.makeAttribute( attributes.getLocalName(i), attributes.getURI(i), attributes.getValue(i), attributes.getType(i) == "ID" ? Attribute.Type.ID : Attribute.Type.CDATA)); } return rv; } catch (XMLException e) { fatal(e); throw new RuntimeException("Unreachable"); } }
Example #6
Source File: XmlBodyWrite.java From rest-client with Apache License 2.0 | 5 votes |
private static void addContentTypeCharsetAttribute(ContentType c, Element e) { if(c != null) { e.addAttribute(new Attribute("content-type", c.getContentType())); if(c.getCharset() != null) { e.addAttribute(new Attribute("charset", c.getCharset().name())); } } }
Example #7
Source File: XMLCollectionUtil.java From rest-client with Apache License 2.0 | 5 votes |
public static void writeRequestCollectionXML(final List<Request> requests, final File f) throws IOException, XMLException { XmlPersistenceWrite xUtl = new XmlPersistenceWrite(); Element eRoot = new Element("request-collection"); eRoot.addAttribute(new Attribute("version", Versions.CURRENT)); for(Request req: requests) { Element e = xUtl.getRequestElement(req); eRoot.appendChild(e); } Document doc = new Document(eRoot); xUtl.writeXML(doc, f); }
Example #8
Source File: PermissionUtils.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static byte[] createPermissionsXml(Permission... permissions) { final Element permissionsElement = new Element("permissions"); permissionsElement.setNamespaceURI("http://xmlns.jcp.org/xml/ns/javaee"); permissionsElement.addAttribute(new Attribute("version", "7")); for (Permission permission : permissions) { final Element permissionElement = new Element("permission"); final Element classNameElement = new Element("class-name"); final Element nameElement = new Element("name"); classNameElement.appendChild(permission.getClass().getName()); nameElement.appendChild(permission.getName()); permissionElement.appendChild(classNameElement); permissionElement.appendChild(nameElement); final String actions = permission.getActions(); if (actions != null && ! actions.isEmpty()) { final Element actionsElement = new Element("actions"); actionsElement.appendChild(actions); permissionElement.appendChild(actionsElement); } permissionsElement.appendChild(permissionElement); } Document document = new Document(permissionsElement); try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { final NiceSerializer serializer = new NiceSerializer(stream); serializer.setIndent(4); serializer.setLineSeparator("\n"); serializer.write(document); serializer.flush(); return stream.toByteArray(); } catch (IOException e) { throw new IllegalStateException("Generating permissions.xml failed", e); } }
Example #9
Source File: XomCreateXML.java From maven-framework-project with MIT License | 5 votes |
/** * 屬性 */ @Test public void test04() { BigInteger low = BigInteger.ONE; BigInteger high = BigInteger.ONE; Element root = new Element("Fibonacci_Numbers"); for (int i = 1; i <= 10; i++) { Element fibonacci = new Element("fibonacci"); fibonacci.appendChild(low.toString()); Attribute index = new Attribute("index", String.valueOf(i)); fibonacci.addAttribute(index); root.appendChild(fibonacci); BigInteger temp = high; high = high.add(low); low = temp; } Document doc = new Document(root); try { Serializer serializer = new Serializer(System.out, "ISO-8859-1"); serializer.setIndent(4); serializer.setMaxLength(64); serializer.write(doc); } catch (IOException ex) { System.err.println(ex); } }
Example #10
Source File: XomCreateXML.java From maven-framework-project with MIT License | 5 votes |
/** * 聲明Document Type */ @Test public void test05() { BigInteger low = BigInteger.ONE; BigInteger high = BigInteger.ONE; Element root = new Element("Fibonacci_Numbers"); for (int i = 1; i <= 10; i++) { Element fibonacci = new Element("fibonacci"); fibonacci.appendChild(low.toString()); Attribute index = new Attribute("index", String.valueOf(i)); fibonacci.addAttribute(index); root.appendChild(fibonacci); BigInteger temp = high; high = high.add(low); low = temp; } Document doc = new Document(root); DocType doctype = new DocType("Fibonacci_Numbers", "fibonacci.dtd"); doc.insertChild(doctype, 0); try { Serializer serializer = new Serializer(System.out, "ISO-8859-1"); serializer.setIndent(4); serializer.setMaxLength(64); serializer.write(doc); } catch (IOException ex) { System.err.println(ex); } }
Example #11
Source File: XomWriter.java From lams with GNU General Public License v2.0 | 4 votes |
public void addAttribute(final String name, final String value) { top().addAttribute(new Attribute(encodeAttribute(name), value)); }
Example #12
Source File: SimpleNodeFactory.java From caja with Apache License 2.0 | 2 votes |
/** * <code>return new Attribute(localName, uri, value, type);</code> * @param localName * @param uri * @param value * @param type * @return */ public Attribute makeAttribute(String localName, String uri, String value, Type type) { return new Attribute(localName, uri, value, type); }