
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
com.nfbsoftware:java-xml
Advanced tools
The NFB Software Java-XML was created to help developers deal with common problems when dealing with String data in the forms of raw strings and XML files.
Java-XML is Java library designed to help simplify the building and parsing of XML documents
The easiest way to incorporate the JAR into your Java project is to use Maven. Simply add a new dependency to your pom.xml
:
<dependency>
<groupId>com.nfbsoftware</groupId>
<artifactId>java-xml</artifactId>
<version>1.0.16</version>
</dependency>
The easiest way to get started is to just use the XmlDocument class, like this:
IXmlDocument doc = new XmlDocument();
IXmlElement testElement = doc.createChild("Test", "");
testElement.createChild("TestOne", "something");
testElement.createChild("TestTwo", "something else");
testElement.createChild("TestThree", "yet another something");
System.out.println(doc.toString());
Getting a handle to an existing element
IXmlDocument doc = new XmlDocument();
IXmlElement testElement = doc.createChild("Test", "");
testElement.createChild("TestOne", "something");
testElement.createChild("TestTwo", "something else");
testElement.createChild("TestThree", "yet another something");
String elementValue = testElement.getChildValue("TestOne");
System.out.println("elementValue: " + elementValue);
Creating an attribute on an element
IXmlDocument doc = new XmlDocument();
IXmlElement testElement = doc.createChild("Test", "");
testElement.createChild("TestOne", "something");
testElement.createChild("TestTwo", "something else");
IXmlElement thirdElement = testElement.createChild("TestThree", "yet another something");
thirdElement.setAttribute("ID", "123456789");
System.out.println(doc.toString());
Get an element using xPath
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>");
xmlString.append(" <two>");
xmlString.append(" <three>test3</three>");
xmlString.append(" </two>");
xmlString.append(" </one>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
// Make an XPath call to get a handle on the third node.
IXmlElement nodeThree = root.getChild("one/two/three");
System.out.println("thirdValue: " + nodeThree.getValue());
Select/search for elements using xPath
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>");
xmlString.append(" <two>");
xmlString.append(" <element id=\"1\">Element-100</element>");
xmlString.append(" <element id=\"2\">Element-200</element>");
xmlString.append(" <element id=\"3\">Element-300</element>");
xmlString.append(" </two>");
xmlString.append(" </one>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
// Make an XPath call to get a handle on children with a matching xpath
List<IXmlElement> elements = root.selectChildren("//element");
List<String> elementValues = new ArrayList<String>();
for(IXmlElement tmpElement : elements)
{
String tmpValue = tmpElement.getValue();
System.out.println("tmpValue: " + tmpValue);
}
Select/search for a single element using xPath. Exception is throw if multiple are found.
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>");
xmlString.append(" <two>");
xmlString.append(" <element id=\"1\">Element-100</element>");
xmlString.append(" <element id=\"2\">Element-200</element>");
xmlString.append(" <element id=\"3\">Element-300</element>");
xmlString.append(" </two>");
xmlString.append(" </one>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
// Make an XPath call to get a handle to the child using an xpath query. An exception will be thrown if multiple matches are found.
IXmlElement tmpElement = root.selectChild("//element[@id='2']");
System.out.println("tmpValue: " + tmpElement.getValue());
Get a CDATA Section
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>");
xmlString.append(" <column>");
xmlString.append(" <name>order</name>");
xmlString.append(" <value><![CDATA[1234]]></value>");
xmlString.append(" </column>");
xmlString.append(" </one>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
// Make an XPath call to get a handle on the column element
IXmlElement columnNode = root.getChild("one/column");
String cdataValue = columnNode.getCDATASection("value");
Set a CDATA Section
IXmlDocument doc = new XmlDocument();
IXmlElement testElement = doc.createChild("Test", "");
testElement.createChild("TestOne", "something");
testElement.createChild("TestTwo", "something else");
IXmlElement cdataElement = testElement.createChild("TestCDATA", "");
cdataElement.setCDATASection("MYCDATATEST");
System.out.println(doc.toString());
Creating an XmlDocument from a string
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>test1</one>");
xmlString.append(" <two>");
xmlString.append(" <three>test3</three>");
xmlString.append(" </two>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
IXmlElement nodeTwo = root.getChild("two");
IXmlElement nodeThree = nodeTwo.getChild("three");
String thirdValue = nodeThree.getValue();
System.out.println("thirdValue: " + thirdValue);
Creating an XmlDocument from a file
File myXmlFile = new File("my-xml-file.xml");
IXmlDocument doc = new XmlDocument(myXmlFile);
IXmlElement testElement = doc.createChild("Test", "");
testElement.createChild("TestOne", "something");
testElement.createChild("TestTwo", "something else");
testElement.createChild("TestThree", "yet another something");
String elementValue = testElement.getChildValue("TestOne");
System.out.println("elementValue: " + elementValue);
Remove an XmlElement
IXmlDocument doc = new XmlDocument();
IXmlElement testElement = doc.createChild("Test", "");
testElement.createChild("TestOne", "something");
testElement.createChild("TestTwo", "something else");
testElement.createChild("TestThree", "yet another something");
// Delete element
testElement.removeChild("TestOne");
System.out.println(testElement.toString());
Remove an XmlElement using XPath
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>");
xmlString.append(" <two>");
xmlString.append(" <element id=\"1\">Element-100</element>");
xmlString.append(" <element id=\"2\">Element-200</element>");
xmlString.append(" <element id=\"3\">Element-300</element>");
xmlString.append(" </two>");
xmlString.append(" </one>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
// Delete element
root.removeChildWithXpath("//element[@id='2']");
System.out.println(root.toString());
Remove multiple XmlElements using XPath
StringBuffer xmlString = new StringBuffer();
xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<ROOT>");
xmlString.append(" <one>");
xmlString.append(" <two>");
xmlString.append(" <element id=\"1\">Element-100</element>");
xmlString.append(" <element id=\"2\">Element-200</element>");
xmlString.append(" <element id=\"3\">Element-300</element>");
xmlString.append(" </two>");
xmlString.append(" <three>");
xmlString.append(" <element id=\"1\">Element-101</element>");
xmlString.append(" <element id=\"2\">Element-201</element>");
xmlString.append(" <element id=\"3\">Element-301</element>");
xmlString.append(" </three>");
xmlString.append(" </one>");
xmlString.append("</ROOT>");
IXmlDocument doc = new XmlDocument(xmlString.toString());
IXmlElement root = doc.getRootElement();
// Delete element
root.removeChildrenWithXpath("//element[@id='2']");
System.out.println(root.toString());
FAQs
Unknown package
We found that com.nfbsoftware:java-xml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.