Parse attribute of Media Element - c#-4.0

I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};

For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f

Related

Storing and retreiving long strings in XPages

I want to work with long strings (size minimum: 100kb) on Xpages. I assume the best method to store a large string is in a data field of the type "Rich Text".
Right now I am stuck with the data handing of this string. How can I transfer this string between server and client?
So far I tried:
data binding controls: Rich text field (Problem: formats the text, tags), text field (Problem: does not work after a certain size)
implementing a rest service: The response body will be cut off at a certain point
<xe:restService pathInfo="getTestString">
<xe:this.service>
<xe:customRestService>
<xe:this.doGet><![CDATA[#{javascript:var id = context.getUrlParameter("documentId");
session.getCurrentDatabase().getDocumentByID(id).getItemValueString("test");}]]></xe:this.doGet>
</xe:customRestService>
</xe:this.service>
</xe:restService>
var url = new URL(window.location.href);
var documentId = url.searchParams.get("documentId");
xhr.open('GET', './rest.xsp/getTestString?documentId=' + documentId, true);;
xhr.send(null);
xhr.response;
So I was wondering whether I missed out on a configuration of my REST Service. Which other alternatives are available to transfer large data between client and server on Xpages?
I tested your scenario. doc.getItemValueString() only reads 64 KB of data from the rich text field. If you want all data you can use (in SSJS):
var doc = database.getDocumentByUNID(id);
var item:NotesRichTextItem = doc.getFirstItem('test');
return item.getUnformattedText();
Looks like that method return the exact text from the rich text item, no paragraph characters are inserted.

Getting value of key from Web Content Display Portlet

I got a requirement. I have added two text fields Value and Key from structure in Web Content Display portlet.
right now in the portlet i am getting value from hard code like below.
BasicModel model = (BasicModel)requestContext.getFlowScope().get("BasicModel");
if(model == null){
model = new BasicModel();
}
model.setEmployeeId("AB1223344S");
model.setHireDate("01-Jan-2000");
model.setNiNumber("AB123456S");
model.setDateOfBirth("12-Dec-1980");
model.setBasicForm(new BasicDetailsForm());
}
but what i want is to get the value of each attribute from web content. Like, If i have given lfr.intel.empid as key and ABSD1822D as value in the added web content structure field like this.
and we can fetch the value of key like this.
model.setEmployeeId(lfr.intel.empid);
You can write a custom function for this which passes the key to that function, now that function will use the JournalArticleLocalServiceUtil API to get respective value from the DB.
Now you need to find How to fetch values from JournalArticleLocalServiceUtil, which you can google or this link can help you.
Thanks.
Try this, assuming that you could get the JournalArticle object, I've done it using the resourcePrimKey
long resourcePrimKey = 12345; //hard coded the resourcePrimKey
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey);
com.liferay.portal.kernel.xml.Document document = SAXReaderUtil.read(article.getContentByLocale("en_US"));
Node keyNode = document.selectSingleNode("/root/dynamic-element[#name='Key']/dynamic-content");
String key = keyNode.getStringValue();
Node valueNode = document.selectSingleNode("/root/dynamic-element[#name='Value']/dynamic-content");
String value = valueNode .getStringValue();

What type of data goes into the <PDFBytes> for DocuSign composite templates?

The specific scenario that we are attempting to solve for our API solution is to create an envelope using a template and to replace the template document with a user specified document. DocuSign's documentation on creating a composite template show the steps for the serverside template and inline templates clearly, and this functionality is working correctly for us. However, the portion of the XML string containing the alternate document does not affect the template. Here is the link to DocuSign's example followed by the code snippet regarding document portion of the composite template.
https://www.docusign.com/p/APIGuide/Content/Sending%20Group/Rules%20for%20CompositeTemplate%20Usage.htm
<Document>
<ID>1</ID>
<Name>Form Document</Name>
<PDFBytes>PDF_BYTES_GO_HERE</PDFBytes>
<TransformPdfFields>true</TransformPdfFields>
<FileExtension>pdf</FileExtension>
</Document>
We have tried multiple variations of breaking down the pdf into bytes to insert into the "PDF_BYTES_GO_HERE" portion.
Here is the code we used to get the pdf bytes, convert them to a string and insert into the tag.
Dim fs As FileStream
fs = File.Open(filePath, FileMode.Open)
Dim bytes As Byte() = New Byte(fs.Length - 1) {}
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim byteString As String = System.Convert.ToBase64String(bytes, 0, bytes.Length)
byteString is the string that we then use in the XML string.
"<Document>" & _
"<documentId>1</documentId>" & _
"<name>DOCUSIGN API TEST</name>" & _
"<PDFBytes>" & byteString & "</PDFBytes>" & _
"<TransformPdfFields>false</TransformPdfFields>" & _
"<FileExtension>pdf</FileExtension>" & _
"</Document>" & _
What type of data is expected within the tag and what is the best way to convert a pdf into that data?
Based on the documentation you've linked to, and the code sample you included, it seems as though you're using the DocuSign SOAP API. If that's the case, then the DocuSign SOAP API guide will be a useful reference for you. As the guide specifies, the PDFBytes property expects a base64-encoded byte stream that represents the document contents:
Are you manually constructing the XML payload? If so, you might instead want to consider adding a Service Reference to your project for the DocuSign WSDL, and then using the proxy classes (i.e., DocuSign object model) that come from that to construct the payload and subsequently send the envelope. If you go this route, the API guide contains code examples in a couple different languages that illustrate the setting of the PDFBytes property during Envelope creation -- starting on page 62. For example:
C#
// Attach the document(s)
envelope.Documents = new DocuSignWeb.Document[1];
DocuSignWeb.Document doc = new DocuSignWeb.Document();
doc.ID = "1";
doc.Name = "Document Name";
doc.PDFBytes = [Location of Document];
envelope.Documents[0] = doc;
PHP
// Attach the document
$doc = new Document();
$doc->ID = "1";
$doc->Name = "Picture PDF";
$doc->PDFBytes = file_get_contents("docs/picturePdf.pdf");
$env->Documents = array($doc);
Perhaps try modeling your approach after one of these examples (in VB, rather than C# or PHP)?

JSON.Net SerializeXnode excluding certain nodes

I have a xml string that i'm trying to convert to JSON using JSON.Net. The problem is that i want only certain part of this xml in my JSON string. Below is the code i use and what i need.
var x = XDocument.Parse(xmlString);
var json = JsonConvert.SerializeXNode(x);
This will convert the whole doc. This is how json string looks like in a JSON Viewer
What i want is ONLY the table (The Arrowed one in image 1) and its descendants to be inside string json.
Is it possible? How to achieve it? Can i use a custom ContractResolver with SerializeXnode?
You've got an XDocument, so why not simply select the part you want and then serialize just that part?
Try something like this:
var doc = XDocument.Parse(xmlString);
var table = doc.XPathSelectElement("//table[#class=\"form\"]");
var json = JsonConvert.SerializeXNode(table);
Note that XPathSelectElement is an extension method, so you will need using System.Xml.XPath; at the top of your code if you don't already have it.
EDIT
You can do it without XPath like this:
var doc = XDocument.Parse(xmlString);
var table = root.Descendants(XName.Get("table"))
.Where(e => e.Attributes(XName.Get("class"))
.Select(a => a.Value)
.FirstOrDefault() == "form")
.First();
var json = JsonConvert.SerializeXNode(table);
Both approaches give the same results, the table plus all descendants.

Reading Signature lines using OpenXMlSDK

I just started office development and have been trying to read a word 2013 document that holds signature fields in it using open xml sdk
can some one help me how to do that.
using (var document = WordprocessingDocument.Open(#"D:\Temp_Folder\tempfile.docx", false))
{
var docPart = document.MainDocumentPart;
}
I have tried reading word file using ELdos (SBOffice) I can get signature lines but not able to get full details related to Signature Lines like Suggested Signer and Suggested Signer email.
Can some one suggest me which I have to prefer OpenXMLSDK or Eldos(SBOffice) bcz i need to find signature fields and then sign them by custom certificate using Third party Signing Service.
The best way would be to use the OpenXMLSDKTool to open the document and it will show you the code necessary to replicate it. I believe it would be within a shape something like
using (var document = WordprocessingDocument.Open("YourDoc.docx", false)
{
var signature = document.MainDocumentPart.Document.Descendant<DocumentFormat.OpenXML.VML.Office.SignatureLine>().FirstOrDefault();
var suggestedSigner = signature.SuggestedSigner;
var suggestedSignerTitle = signature.SuggestedSigner2;
var suggestedSignerEmail = signature.SuggestedSIgnerEmail;
}
You could get the actual signature image in this same area.

Resources