2016年7月12日 星期二

read xml string data xml2value


<script>
var dataX='<resultSet>'+uiDisplay("<content recordid='146944229507925'><user_recordid>1386746903848</user_recordid><mode>request</mode><datetime>2016-07-25 18:24:55</datetime><user>lee</user><message>TEST 201607251824 AAA</message><follower_read>2016-07-25 18:25:22</follower_read></content><content recordid='146944232902265'><user_recordid>1386746903848</user_recordid><mode>reply</mode><datetime>2016-07-25 18:25:29</datetime><user>lee</user><message>ANSER DSF</message><request_read>2222016-07-25 18:25:40</request_read></content>")+'</resultSet>';


var xml = $.parseXML(dataX);
var $xml = $(xml);
$xml.find('resultSet').each(function(){
console.log(this);

$(this).children().each(function(){

alert($(this).attr("recordid")); = 146944229507925
alert($(this).text());
alert($(this).html());

  $(this).children().each(function(){alert(this.tagName+ '  '+$(this).text());});


alert($(this).children()[0].tagName);
alert($(this).children()[1].tagName);


var message_user=$(this).find('user').text();
alert(message_user);

});
});

</script>


/***************************************************/



/*
var dataX='<bookstore> <book category="cooking"> <title lang="ch">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="children"> <title lang="fa">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> <book category="web" cover="paperback"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>';
var xml = $.parseXML(dataX);
var $xml = $(xml);
$xml.find('bookstore').each(function(){
console.log(this);
$(this).children().each(function(){
console.log(this);
console.log(this.tagName);
console.log($(this).attr("category"));
var tagName=this.tagName;
var val=$(this).text();
var html=$(this).html();
console.log('Title : Language ',$(this).find('title').attr('lang'));
console.log('Title : Value ',$(this).find('title').text());
console.log('author ',$(this).find('author').text());
});
});
*/






/*********************************************/











var dataX='<bookstore> <book category="cooking"> <title lang="ch">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="children"> <title lang="fa">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> <book category="web" cover="paperback"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>';



var xml = $.parseXML(dataX);
var $xml = $(xml);
$xml.find('bookstore').each(function(){
console.log(this);
$(this).children().each(function(){
console.log(this);
console.log(this.tagName);
console.log($(this).attr("category"));
var tagName=this.tagName;
var val=$(this).text();
var html=$(this).html();
console.log('Title : Language ',$(this).find('title').attr('lang'));
console.log('Title : Value ',$(this).find('title').text());
console.log('author ',$(this).find('author').text());
});
});

2016年7月10日 星期日

iText - add content to existing PDF file insertField insert field

http://stackoverflow.com/questions/3335126/itext-add-content-to-existing-pdf-file



// Create output PDF
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
PdfContentByte cb = writer.getDirectContent();

// Load existing PDF
PdfReader reader = new PdfReader(templateInputStream);
PdfImportedPage page = writer.getImportedPage(reader, 1); 

// Copy first page of existing PDF into output PDF
document.newPage();
cb.addTemplate(page, 0, 0);

// Add your new data / text here
// for example...
document.add(new Paragraph("my timestamp")); 

document.close();

int left=27;
int top=-10;
PdfContentByte cb = writer.getDirectContent();
FileInputStream templateInputStream= new FileInputStream("/erp/images/PrePrintForm.pdf");
PdfReader reader = new PdfReader(templateInputStream);
PdfImportedPage page = writer.getImportedPage(reader, 1);
document.newPage();
cb.addTemplate(page, left, top);
document.add(pCard.pCard());
document.add(pCard.pCardBody());