Using VB.net to write an Ebay Motors Pro xml file - mysql

I am struggling to make this work and have trawled for examples on how to fix this to no avail. I am converting a mysql resultset into an xml file to upload to ebaymotorspro. I thought this would be relatively simple and yet I am struggling with the conventions set out by both ebay and the .net framework.
The opening element of the file has to read:
<empro xmlns="urn:de:mobile:emp:inventory:xml:uk:car" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:de:mobile:emp:inventory:xml:uk:car http://www.ebaymotorspro.co.uk/schema/empro-car-uk.xsd">
I am using the xmlwriter class to recreate this and have this so far:
Using writer as XmlWriter = XmlWriter.Create(feedfile, xmlsettings)
writer.WriteStartDocument(True)
writer.WriteStartElement("empro", "urn:de:mobile:inventory:xml:uk:car")
' This Bit is causing the issue
writer.WriteAttributeString("xmlns", "xsi", "http://www.w3.org/2001/XMLScema-instance")
End Using
I end up with the following code in the xml file:
<empro p1:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p1="xmlns" xmlns="urn:de:mobile:emp:inventory:xml:uk:car" />
Which isnt correct, can anyone please point me in the right direction to make this output the correct document header?
Many thanks
Graham

The part that causing you a trouble should've been written using WriteAttributeString() overload which accept four parameters :
' This Bit is causing the issue'
writer.WriteAttributeString("xmlns", "xsi", Nothing, "http://www.w3.org/2001/XMLScema-instance")
Anyway, I will personally do this using LINQ-to-XML. VB even has exclusive features which C# doesn't for constructing XML : XML literals with embedded expression support. For example :
Dim contactName As String = "Patrick Hines"
Dim contact As XElement =
<contact><%= contactName %></contact>
Console.WriteLine(contact.ToString())
'output :'
'<contact>Patrick Hines</contact>'
Source : MSDN: Creating XML in Visual Basic

Related

Powerbuilder cannot Encode/decode URL's parameters

I use the powerbuilder ole object to encode/decode the string like JSON, but when I use the ole object, I don't know how put my data to encoding it
Here is my testing data:
my testing data is like that [{"ref":"T213445677","pickdtime":"2018-02-02 09:00:00","compname":"Wing Kei Shoes Company"}]
Here is my coding
OleObject wsh
Integer li_rc
string ls_temp
wsh = CREATE OleObject
li_rc = wsh.ConnectToNewObject( "MSScriptControl.ScriptControl" )
wsh.language = "javascript"
ls_temp = wsh.Eval("escape('[{"ref":"T213445677","pickdtime":"2018-02-02
09:00:00","compname":"Wing Kei Shoes Company"}]')")
MessageBox( "ESCAPE" , ls_temp)
ls_temp = wsh.Eval("unescape('" + ls_temp + "')")
MessageBox( "UNESCAPE" , ls_temp)
You might want to look at this article regarding a JSON parser written in Visual Basic for Applications (VBA). It can be found here: http://ashuvba.blogspot.com/2014/09/json-parser-in-vba-browsing-through-net.html
The current version of PowerBuilder (2017 R2) has native JSON parsing built into the datawindow.
I have an example app that shows how to post messages to Twitter from PowerBuilder. It includes functions for encoding. The zip file includes PB 8 and PB 10 versions.

How to set decimal mark character or localization in CSVeed?

new Problem: my employer wishes me to implement CSVeed utility for a project. It works just fine except that data formatting is not recognised correctly. The data to read is formatted with semicolon (;) as field separator and colon (,) as decimal mark. The information on the projects home page is telling me that decimal conversion is done automatically, but e.g. a string 0,5 in csv file is interpeted as 5, a string 9,5 read as 95. In the source code of the project i find Information: "Makes sure that a specific Locale is used to convert numbers.". I am not exactly sure where to tell the csveed lib which l10n to use. At another point of source doc it says utility will use l10n of framework. Is this from Eclipse RCP which i am using oder from the machine ? Sorry for not posting any code, but i didnt find barely a hint where to setup
the decimal mark in the utility...
Anyone an idea ?
Greetings :)
My Goodness, why this verbose ? ^^
CsvClient<BeanClass> reader = new CsvClientImpl<BeanClass>(reader, BeanClass.class);
reader.setConverter("[name of property]", new CustomNumberConverter(Double.class, NumberFormat.getNumberInstance(Locale.[whereever]), false));
[name of property] has to be the name of the actual instance variable.
Greetings :)

Find a specific string in html source

My goal is to find a predefined string in an HTML source of a specific site that I have extracted using c++, but I'm getting some errors. Here is my source code so far:
So after I connect to the internet and the site and all I have this...
addr = InternetOpenUrl...
dmbp = char dmbp[5000]
dba = DWORD dba = 0
while (InternetReadFile(addr, dmbp, 80000, &dba) && dba)
{
string str2 = dmbp;
size_t sf1 = str2.find(string1);
if (sf1!=string::npos)
{printf("found");
// manipulate it...
}else{printf("not found");}
}
My problem is that it never actually confirms that it found the value that I need, it always says that the value is not found, but I even statically insert the page and look at myself and i can see the value that i need, it just doesnt show up. Does anyone with experience in html extraction with c++ know what I'm missing or how I can get this to work?
There is nothing wrong with the string search code as far as I can see, the problem is that we don't know exactly what you are searching for.
As pure HTML can be full of special characters (such as " or ", the string you might be looking for should deal with those characters. Also, strings can contain newlines and html tags (such as <b></b> within a single word), and they should be specified in the search string as string::find looks for an exact match (including any newline).
Also, I suggest debugging your code and see if the website's text/code is actually loaded into str2.
Looking at the information given that's currently the only issue I can think of why your code doesn't work.

AXE - Asp Xtreme Evolution - Json parser for classic asp

Has anyone ever used this and got it working? I'm having real problems because it's telling me there is a JScript error and I'm not sure how to fix it.
Links on this are here to get some background on the product, but it's a JSON parser for classic asp.
Iterating though a JSON return using ASP Xtreme Evolution
I'm sure I had this working the other other day, but now I've come back to it, it's throwing a JScript error, and I can't seem to make it work now.
So, I'm posting JSON to a classic asp page, this is the code I'm using to include the json2.asp page as instructed in all the tutorials:
<%#LANGUAGE="VBSCRIPT"%>
<!--#include file="json2.asp"-->"%>
<% 'json processing details here..
The error it throws is on a line of json2.asp and it's a JScript error. Here is the exact error:
Microsoft JScript compilation error '800a03ea'
Line 765 json2.asp
I believe this is a version of Crockfords json2.js and I think the reason it's in an asp page is so it can use JScript, but it's not progressing for me. Anyone have any idea what I'm talking about that could help me out before I tear all my hair out?!
Let me know if you need more info - many thanks
UPDATE
Here is line 765 (in the middle between the comments)
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '#').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function' ?
walk({'': j}, '') : j;
}
You're not including the right things. You need the whole library available and to include the following files (change your paths appropriately).
<!-- #include file="includes/extlib/axe/base.asp" -->
<!-- #include file="includes/extlib/axe/classes/Parsers/json.class.asp" -->
Then to actually use, you do something like this:
set oJson = new Json
oJson.loadJson(strJSON)
strSomething = oJson.getElement("theElement")
set oJson = nothing
All this taken from working code.

Need help preforming an XSL Transform from XML to HTML in ASP.NET MVC

I just learned about XSL and XSLT a few days ago and now I'm trying to put it to work based on a question I had earlier today (want to have formated XML displayed on my website).
Here is the code I'm trying (in a View):
XDocument xmlInput = XDocument.Parse(item.Action);
XDocument htmlOutput = new XDocument();
using (System.Xml.XmlWriter writer = xmlInput.CreateWriter())
{
// Load Transform
System.Xml.Xsl.XslCompiledTransform toHtml = new System.Xml.Xsl.XslCompiledTransform();
string path = HttpContext.Current.Server.MapPath("~/App_Data/xmlverbatimwrapper.xsl");
toHtml.Load(path);
// Execute
toHtml.Transform(xmlInput.CreateReader(), writer);
}
Response.Write(htmlOutput.ToString());
And it's giving me this error:
[InvalidOperationException: This operation would create an incorrectly structured document.]
Not sure if it's along the right lines, but I've tried modifying the writers settings so it can produce fragmented xml files with no luck (since it's readonly). Any ideas to get this working? Perhaps I'm going about completely the wrong approach? :)
Thanks for your help!
I got the above code working by looking at this site
The code I ended up using (which was copied from the link above with a few changes for my specific situation) was:
String TransactionXML = item.Action;
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.IO.Stream xmlStream;
System.Xml.Xsl.XslCompiledTransform xsl = new System.Xml.Xsl.XslCompiledTransform();
ASCIIEncoding enc = new ASCIIEncoding();
System.IO.StringWriter writer = new System.IO.StringWriter();
// Get Xsl and XML
xsl.Load(HttpContext.Current.Server.MapPath("~/App_Data/xmlverbatimwrapper.xsl"));
xmlDoc.LoadXml(TransactionXML);
// Get the bytes
xmlStream = new System.IO.MemoryStream(enc.GetBytes(xmlDoc.OuterXml), true);
// Load Xpath document
System.Xml.XPath.XPathDocument xp = new System.Xml.XPath.XPathDocument(xmlStream);
// Perform Transform
xsl.Transform(xp, null, writer);
// output
Response.Write(writer.ToString());
Hope this helps someone! :)
Just a guess, but valid HTML is not necessarily valid XML, and you're using a class called XmlWriter. Without seeing your XSL and input XML it's kind of hard to figure out what's going. I suspect your output document is not well-formed XML.
I would guess you need to provide a different Writer implementation that can deal with HTML output.