NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

FORMÉPÍTŐ METÓDUS:
public void ListtagsReq(Node root, int i)
{
NodeList children=root.getChildNodes();
int z=children.getLength();
//gyermekelem
if(z<2)
{
if(root.getNodeName().toString()!="#text")
{
xmlfields.setText(xmlfields.getText()+root.getNodeName()+"n");
tf.add(new TagField(root.getNodeName()));
tf.get(tf.size()-1).setBounds(50, (i*100)+20, 200, 30);
//add(tf.get(i));
p.add(tf.get(tf.size()-1));
}
if(root.getNextSibling()!=null)
ListtagsReq(root.getNextSibling(), i++);
}
//szülőelem
else
{
parenttags.add(new JLabel(root.getNodeName().toString()));
parenttags.get(parenttags.size()-1).setAlignmentX(Component.LEFT_ALIGNMENT);
parenttags.get(parenttags.size()-1).setBounds(0, 0, 200, 30);
p.add(parenttags.get(parenttags.size()-1));
ListtagsReq(root.getFirstChild(), i++);
parenttags.add(new JLabel("--------------"));
parenttags.get(parenttags.size()-1).setBounds(0, 0, 200, 30);
p.add(parenttags.get(parenttags.size()-1));
if(root.getNextSibling()!=null)
ListtagsReq(root.getNextSibling(), i++);
}

}
XMLPARSER OSZTÁLY:

package pack;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class XMLHandler {

private DocumentBuilderFactory dbf;
private DocumentBuilder db;
private Document doc;

public XMLHandler(String filename)
{
Loadxml(filename);
}

private void Loadxml(String filename)
{
File file = new File(filename);
dbf = DocumentBuilderFactory.newInstance();
try {
db = dbf.newDocumentBuilder();
setDoc(db.parse(file));
getDoc().getDocumentElement().normalize();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
public void Savexml(String filename, ArrayList<TagField> tf)
{
char z;
String xml="";
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = factory.newTransformer();
StringWriter writer = new StringWriter();
Result result = new StreamResult(writer);
Source source = new DOMSource(doc);
transformer.transform(source, result);
writer.close();
xml = writer.toString();
} catch (TransformerConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String rest="", maradek="", rootelement="";
boolean root=true;
for(int a=0;a<xml.length()-1;a++)
{
if(xml.charAt(a)=='>')
{
rest=xml.substring(a+1);
maradek=rest.substring(rest.indexOf("<"));
if(root && maradek.charAt(1)!='?')
{root=false; rootelement="</"+maradek.substring(1,maradek.indexOf(">")+1);}
if(maradek.charAt(1)!='/'){
maradek="n"+maradek;
}
else if(maradek.substring(1).charAt(maradek.substring(1).indexOf("<")+1)=='/')
maradek=maradek.substring(0,maradek.indexOf(">"))+"n"+maradek.substring(maradek.indexOf(">")+1);
xml=xml.substring(0,a+1)+maradek;
}
}
xml=xml.substring(0,xml.lastIndexOf("<"))+"n"+xml.substring(xml.lastIndexOf("<"));
String[]xmllines=xml.split("n");
for(int x=0;x<xmllines.length;x++)
{
while(xmllines[x].contains("/>"))
{
String m=xmllines[x].substring(1,xmllines[x].indexOf("/>"));
m="<"+m+"></"+m+">";

if(xmllines[x].substring(xmllines[x].indexOf("/>")).length()>2)
m=m+"n"+xmllines[x].substring(xmllines[x].indexOf("/>")+2);
xmllines[x]=m;
}
}
xml="";
int input=0;
for(String x:xmllines)
{
if(x.charAt(x.length()-1)!='>' && x.charAt(x.length()-1)!='n' )
x+=">";
if(input<tf.size()){
String s=tf.get(input).label.getText();
if(x.contains(s.replaceAll(":","")))
{
x=x.substring(0,x.indexOf(">")+1)+tf.get(input).content.getText()+x.substring(x.lastIndexOf("<"));
input++;
}
}
if(x.length()<=2) continue;
xml+=x+"n";
}
//xml=xml.substring(0,xml.lastIndexOf("<"))+"n"+xml.substring(xml.lastIndexOf("<"));
try {
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write(xml);
out.close();
}
catch (IOException e)
{
System.out.println("Exception ");
}
}

public ArrayList<String> GetValues()
{
NodeList nodeList=this.getDoc().getElementsByTagName("*");
ArrayList<String> result=new ArrayList<String>();
for (int i=0; i<nodeList.getLength(); i++)
{
//Get element
Element element = (Element)nodeList.item(i);
NodeList children=element.getChildNodes();
int z=children.getLength();
if(z<2)
{
result.add(element.getTextContent());
}
}
return result;
}

public void setDoc(Document doc) {
this.doc = doc;
}

public Document getDoc() {
return doc;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.