Trouble passing XML text to RIA Services from my client - wcf

I am trying to pass the following XML text to RIA services in a query operation that returns a queryable sequence of entities in response:
<?xml version="1.0" encoding="utf-8"?>
<project>
<item type="Item" filetype="cabinet" category="EZ Workshop" name="EZW Panel Edge-Banded" height="24.000000" width="36.000000" depth="0.725000" quantity="1">
</item>
<item type="Item" filetype="cabinet" category="EZ Furniture" name="Entry Bench" height="19.000000" width="48.000000" depth="17.999999" quantity="1">
</item>
<item type="Item" filetype="cabinet" category="EZ Closet Euro Style" name="CSEKD Tall H3R 28-72W 12-24D" height="84.000000" width="54.000000" depth="19.999999" quantity="1">
</item>
<item type="Item" filetype="assembly" category="EZ Pro ManCave" name="EZ Corn Hole Game-Set" height="0" width="0" depth="0" quantity="1">
</item>
<item type="Item" filetype="assembly" category="EZ Office" name="EZ 30 Printer Stand" height="0" width="0" depth="0" quantity="1">
</item>
<item type="Item" filetype="assembly" category="Corporate Culture Pro" name="C-Table" height="0" width="0" depth="0" quantity="1">
</item>
</project>
This is the query operation:
[Query]
public IQueryable<ProjectItem> GetItemsFromImport(String a_strImportXml)
{
// Return empty sequence for now as a test.
return new ProjectItem[0].AsQueryable();
}
When I pass the full XML, I get that annoying "Not Found" exception, and the break-point in my operation is never hit. I'm using Visual Studio 2010's ASP.NET Development Server. When I get "Not Found" with that it portends bad stuff. The kicker is, when I pass an empty string, I get no exceptions at all, and the break-point is hit.
As you can see its not a tremendously long XML document. Is there some limit to the amount of data sent? Do I have to escape the document?
Thanks.
Edits:
I discovered that I only had to escape the structural characters ('<', '>', and '&') out of the document before I sent it. I'm using String.Replace to do it. Does anyone know if there is a better way to accomplish this. Something similar to Uri.EscapeDataString perhaps?
var strImportXml = a_xImport.ToString();
strImportXml = strImportXml.Replace("&", "&");
strImportXml = strImportXml.Replace("<", "<");
strImportXml = strImportXml.Replace(">", ">");

Ok, so I guess this is standing as the answer to my own question. I discovered that I only had to escape the structural characters ('<', '>', and '&') out of the document before I sent it. I'm using String.Replace to do it. Does anyone know if there is a better way to accomplish this. Something similar to Uri.EscapeDataString perhaps?
var strImportXml = a_xImport.ToString();
strImportXml = strImportXml.Replace("&", "&");
strImportXml = strImportXml.Replace("<", "<");
strImportXml = strImportXml.Replace(">", ">");
NOTE: I'd still like to know if there is a better way to do this.

Related

How can I configure a live template that generates a builder method in IntelliJ IDEA?

I oftentimes need to create builder methods in my code. These methods are similar to getters, but they return this and they use with instead of get.
To be faster with that task I'd like to create a live-template in IDEA.
This how far I got:
(in ~/.IntelliJIdea14/config/templates/user.xml this looks like this:)
<template name="builderMethod" value="public $CLASS_NAME$ with$VAR_GET$(final $TYPE$ $PARAM_NAME$) {
this.$VAR$ = $PARAM_NAME$;
return this;
}" description="create a builder method" toReformat="true" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR" expression="complete()" defaultValue="" alwaysStopAt="true" />
<variable name="PARAM_NAME" expression="VAR" defaultValue="" alwaysStopAt="true" />
<variable name="TYPE" expression="typeOfVariable("this." + VAR)" defaultValue="" alwaysStopAt="true" />
<variable name="VAR_GET" expression="capitalize(VAR)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
This nearly works, except for typeOfVariable("this." + VAR) which does not. I just guessed how to call this method, because I could not find any documentation on the syntax used in the expressions except for this page which does not even mention a script language name or something that would make googling for easier.
How do I fix the call to typeOfVariable?
Bonus question: How can I get complete() for VAR to only show fields?
Similar question but not does not even have a start: Live Template for Fluent-API Builder in IntelliJ
Replace typeOfVariable("this." + VAR) with typeOfVariable(VAR).
Edit:
Another way to generate builder methods is to use an appropriate setter template (instead of live template).
https://www.jetbrains.com/help/idea/2016.1/generate-setter-dialog.html
There is already a built-in setter template named "Builder" which generates setters such as:
public Foo setBar(int bar) {
this.bar = bar;
return this;
}
You can create your own template (e.g by copying it) and change it so that the method prefix is with.
And to make the generated method parameter final go to settings:
Editor | Code Style | Java
Select the Code Generation tab
Tick Make generated parameters final
IntelliJ IDEA add final to auto-generated setters

LINQ-to-XML Selecting tags inside the root

I'm new to LINQ-to-XML and I'm trying to learn the query structure. I have the following XML:
<?xml version="1.0" encoding="utf-8"?>
<list>
<item>
<due>07 May 2012</due>
<name>Name</name>
<desc>Description</desc>
<colour>White</colour>
</item>
<item>
<due>12 May 2012</due>
<name>Name2</name>
<desc>Desc2</desc>
<colour>White</colour>
</item>
</list>
And I'm trying to delete <item> elements with a query:
Dim DeleteItems = From e In Root.Elements("list") Where e.Element("name").Value = Text
However it isn't working. I think it's trying to select tags called <item> in the file's root, however it needs to be selecting <item> tags in the <list> element - which I don't know how to do.
I assume that Root is you XDocument object name.
Change Elements do Descendants and it should work then.
Dim DeleteItems = From e In Root.Descendants("item") Where e.Element("name").Value = Text

Craigslist API - how to post with RSS data?

http://www.craigslist.org/about/bulk_posting_interface - it says, "New postings are submitted to craigslist in RSS format with additional craigslist-specific elements via HTTPS POST"
How do I post a form passing rss data?
I was hoping to just have something like this:
<form action="https://post.craigslist.org/bulk-rss/post" type="post">
<input type="hidden" name="area" value="richmond" />
<input type="hidden" name="category" value="free" />
<input type="hidden" name="reply-email" value="x#y.com" />
</form>
But, it says I have to supply the data in RSS format.
So is it something like this?
<form action="https://post.craigslist.org/bulk-rss/post" type="post">
<input type="hidden" value="{all the RSS data goes here??}" />
</form>
Any help is super appreciated. Eventually I'd like to build an android app that posts to Criagslist, but, just want to get a simple html form to test for proof of concept for now. Thanks!
I've been trying to figure this out, too, but from what I have read about this RSS interface it is only available for non-free categories like employment and real estate postings. Those categories require you to purchase blocks of posting credits.
IMO this is a good reason not to use Craigs List. If anything, they should open up the RSS interface to all categories and perhaps limit the rate of posting for free ads and/or let people buy blocks for other categories.
The format of the request will look like this
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">
<channel>
<items>
<rdf:li rdf:resource="NYCBrokerHousingSample1" />
</items>
<cl:auth username="Vusername#gmail.com" password="password" accountID="14" />
</channel>
<item rdf:about="NYCBrokerHousingSample1">
<cl:category>fee</cl:category>
<cl:area>nyc</cl:area>
<cl:subarea>mnh</cl:subarea>
<cl:neighborhood>Upper West Side</cl:neighborhood>
<cl:housingInfo price="1450" bedrooms="0" sqft="600" />
<cl:replyEmail privacy="C">bulkuser#bulkposterz.net</cl:replyEmail>
<cl:brokerInfo companyName="Joe Sample and Associates" feeDisclosure="fee disclosure here" />
<title>Spacious Sunny Studio in Upper West Side</title>
<description><![CDATA[posting body here]]></description>
</item>
<item rdf:about="NYCBrokerHousingSample2">
<cl:category>fee</cl:category>
<cl:area>nyc</cl:area>
<cl:subarea>mnh</cl:subarea>
<cl:neighborhood>Chelsea</cl:neighborhood>
<cl:housingInfo price="2175" bedrooms="1" sqft="850" catsOK="1" />
<cl:mapLocation city="New York" state="NY" crossStreet1="23rd Street" crossStreet2="9th Avenue" latitude="40.746492" longitude="-74.001326" />
<cl:replyEmail privacy="C" otherContactInfo="212.555.1212">bulkuser#bulkposterz.net</cl:replyEmail>
<cl:brokerInfo companyName="Joe Sample and Associates" feeDisclosure="fee disclosure here" />
<title>1BR Charmer in Chelsea</title>
<description><![CDATA[posting body goes here]]></description>
<cl:PONumber>Purchase Order 094122</cl:PONumber>
<cl:image position="1">/9j/4AAQSkZJRgABAQEASABIAAD/4QCARXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUA
AAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAABIAAAAAQAA
AEgAAAABAAKgAgAEAAAAAQAAABCgAwAEAAAAAQAAABAAAAAA/9sAQwABAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB/9sAQwEBAQEB
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D/iB
8TfhdFcT3LfD34i+A/ilfXWl674bs51zrLQaDcSaXoem6toF6+IatHxS454+8MOKshwOC4pwOM4k
xPh7xNhsAsvzSdPLKmJxuXZXmrgorMstzDKYRq0MTOL/AHPNiIqriKtHEQeaVKfGnEfE/B2dZZh8
PnWGr5vV4WzijhfquNlHByq4jC4PGtcv1vCYrBRU6VaSf7vmqrnqThVj8N/ttfspePP2M9M+NP7L
37Yl/wDHvXP2C/hX8Of2nPHX/BNw/C/wdeap8DtV+PHxWtvGuvfDlP2hPFvhu6TWNE8W/D7xH4lF
lo2k+ILCTTZtXW+1iC50zwFqOuJ4u+84F4ty/jarkfFfBdPh+h4g5tmXC2A8Tf7VxsaWfUeH8ong
cPmT4cwmKi6FfB5jhsM6leth6ntVRcKDjVzCnQ+p/S8N55heIp5bnfD0cqp8U47GZLheMPruIjDM
4ZXgZYeljHlOHrJ06lDF0aLlUqUpe0UHCm1PFQpOg79ib9lPx1+2bpHwU/Zd/Y6vfj5oX7B/xU+H
X7M3jr/gpM3xQ8H3emfAzTfjt8KYPBevfEJf2evFviS6fWda8X/EHxD4baw1zSPD+nx6XFq50/Wp
rrU/Aen6LH4ROOuLcBwTWz3ivjSHD1fxAynMuKMB4YrKsbGrn1XIM3njsPlz4jweFgqFHB5bhsT7
ShWxFV1XR9pQUKWYVKzxhxJnmG4dqZnnfEMcrqcUYHF5zhuD/qWIjPM55ZjpYmlhP7WoUV7OnQwl
KtzUqlWXO6fPTShiZVHi`enter code here`P//Z</cl:image>
</item>
</rdf:RDF>

LINQ to XML. Enumeration yielded no results

I'm having trouble populating an object from an XML file. I've copied an example I've found almost exactly, with variable names changed, but I keep getting the "Enumeration yielded no results" exception.
Here is my code:
Dim element As XElement = XElement.Load(path)
Dim itemProps = From p In element...<Property> _
Where p.<LanguageCode>.Value = "en_us" _
Select p.<Title>.Value, p.<Description>.Value
Using breakpoints, I have confirmed that the 'element' variable is being properly populated using the XElement.Load(path) method.
Here is the XML file that is being accessed:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Items>
<Item ItemID="1">
<Property ItemPropertyID="1">
<Title>Title1</Title>
<Description>Description1</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="2">
<Property ItemPropertyID="2">
<Title>Title2</Title>
<Description>Description2</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="3">
<Property ItemPropertyID="3">
<Title>Title3</Title>
<Description>Description3</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="4">
<Property ItemPropertyID="4">
<Title>Title4</Title>
<Description>Description4</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="5">
<Property ItemPropertyID="5">
<Title>Title5</Title>
<Description>Description5</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
<Item ItemID="6">
<Property ItemPropertyID="6">
<Title>Title6</Title>
<Description>Description6</Description>
<LanguageCode>en-us</LanguageCode>
</Property>
</Item>
</Items>
Essentially, the XML query is supposed to return the title and the description for every Property which has an element called Language Code, which is equal to "en-us". I have a feeling that my problem lies in my XML code.
This language code:
en_us
should be:
en-us
Try taking one of the dots out of
Dim itemProps = From p In element...<Property>
Your going 3 levels down, when you only need to go down 2.
If that doesn't work try just one dot, because essentially the path your travelling is only 1 below the root of the document.

Indesign scripting create deeper structures by adding tags

I first set out to do this with XSLT, then with PHP. Now i'll have to have a go at it with Indesign scripting (javascript probably)
My problem is that i have an indesign file without structure (nothing is tagged, but everything has a paragraph style)
Wat i have to do is
1) ad tags to paragraphs based on their styles
2) deepen the structure by adding parent-elements to the tags
An example:
This text:
Titel 1 (style = title1)
Titel 2 (style = title2)
some text (style = text1)
listitem 1 (style = listitem)
listitem 2 (style = listitem)
Has to become (on export to XML)
<GR.SEQ level="1">
<TITLE>
<TI>
<HT>
Titel 1
</HT>
</TI>
</TITLE>
<GR.SEQ level="2">
<TITLE>
<TI>
<HT>
Titel 2
</HT>
</TI>
</TITLE>
<P>
some text
</P>
<LIST>
<ITEM>
<ITEM.CONT>
listitem 1
</ITEM.CONT>
</ITEM>
<ITEM>
<ITEM.CONT>
listitem 2
</ITEM.CONT>
</ITEM>
</LIST>
</GR>
</GR>
Any help is appreciated! a code-example that does this would be marvelous but a push in the right direction is also very welcome.
I would be very pleased already when i could change this:
Titel 1
to this
<TITLE>
<TI>
<HT>
Titel 1
</HT>
</TI>
</TITLE>
First you have to define an XMLExportMap-Object for each Paragraph/Tag like this:
<yourDoc>.xmlExportMaps.add(<yourParagraphStyle>, <yourParagraphStyle>.name);
(Rather consider that there is no whitespace in your Style-Names)
When you defined all, then you call following method:
<yourDoc>.mapStylesToXMLTags();
As a result there should be a flat XML-structure in the Root-element then
Then: There are some abilities to use Xpath with InDesign and Javascript, but in my opinion hard to use and very less implemented.
So I appreciate to export the flat XML-Structure and apply an XSL-Stylesheet to get a deepened structure.
Hope that helps