QBO3 Attachment/Generate is called,but Attachment/Download fails - c#

Using the QBO3 Import framework, we are generating a mail-merge document using this XML snippet:
<AttachmentItem Operation="Generate">
<Object>ImportForm</Object>
<ObjectSubscriberID>CRLetterCycle-17010353-2442587</ObjectSubscriberID>
<Template>CR CFPB RET Ack Incomplete Appl</Template>
</AttachmentItem>
and in the results, we see:
<Result ID="1816859">
<Object>Attachment</Object>
<ObjectID>524624</ObjectID>
<Operation>Insert</Operation>
<Status>Success</Status>
<Properties>
... [omitted for brevity] ...
</Properties>
</Result>
However, when we attempt to download the merged document by calling:
Attachment/Download?ID=524624
we get and HTTP 500 error, with a response that contains:
The specified file was not found in the '[...]' file object
repository. Parameter name: relativePath Actual value was
qboRoot/ImportForm/1633788/CRLetter.b6e893b7-552e-4298-9495-eaa0fb4e6a34.pdf.
Why do we get a success indicator in the import results, but cannot download the generated file?

When the QBO3 Import Framework processes the XML you provided, there are two method signatures executed:
Attachment/Insert, and
Attachment/Generate
If you inspect your import results XML a bit more, you'll find two nodes related to your attachments; the one you noted in your question, and a second one:
<Result ID="1816860">
<Object>Attachment</Object>
<ObjectID>524624</ObjectID>
<Status>Error</Status>
<Message>Invalid column name 'Item'. [Omitted for brevity]</Message>
<Source>.Net SqlClient Data Provider</Source>
</Result>
In short, the Attachment/Insert worked, creating an Attachment row in the database, but the Attachment/Generate errored, failing to save an actual mail-merged file to disk.
The error rendered in the import results is also logged in the ImportLog table, viewable (and reportable) from:
Design > Import Data > {Imported XML file}

Related

Response.ContentType = "text/xml" causes XML attributes construct error

I have a C# ashx handler that will do some processes and then generate an XML output which should be parsed and sent to the server.
The problem is when I try to set the context Response to txt/xml it will generate the following error:
This page contains the following errors:
error on line 1 at column 226: attributes construct error
Below is a rendering of the page up to the first error
It may look that the problem is with generated XML which may be not formatted well, but I've checked that by getting the output as a string then I used a validator and it was fine.
Any suggestions please to figure it out?
XML Output:
<Response>
<GetDigits action='http://domain/Handler.ashx?ivrlevel=9&language=arb&isOperation=false&dayFrom=3&dayTo=3&hourFrom=12&hourTo=2&minFrom=30&minTo=20&enteredMobileNumber=66355356'>
<Play>http://domain/AllClips/enterednumberis_arb.mp3</Play>
<Play>http://domain/AllClips/6.mp3</Play>
<Play>http://domain/AllClips/6.mp3</Play>
<Play>http://domain/AllClips/3.mp3</Play>
<Play>http://domain/AllClips/5.mp3</Play>
<Play>http://domain/AllClips/5.mp3</Play>
<Play>http://domain/AllClips/3.mp3</Play>
<Play>http://domain/AllClips/5.mp3</Play>
<Play>http://domain/AllClips/6.mp3</Play>
<Play>http://domain/AllClips/numberconfirmation_arb.mp3</Play>
</GetDigits>

Importing XML with 'µ' symbol into excel

I am trying to import an XML file into excel using Data -> Other Sources -> From XML Data import. When the file contains a 'µ' symbol, it gives the following error:
Invalid file reference. The path to the file is invalid, or one or
more of the referenced schemas could not be found.
The XML looks like this:
<root>
<File>
<FileName>Data\7.5 µg_mL Sample.pdf</FileName>
</File>
</root>
If i remove the microgram symbol, it works and Excel imports the data.
I am generating the XML file in .net using XNode.toString(), and if I run the XML through a validator, it returns no errors. It doesn't seem to matter if I put the XML declaration at the top of the file and declare it as UTF-8 or 16 either.
Any pointers welcome, i would ideally like to check for any characters that might cause this problem as i am guessing there are more than just the microgram symbol.
I am passing the XML string to a function that swaps out a custom xml file, i don't seem to have the option to change the file format here..
'Uses Ionic.Zip.ZipFile
Using zip As ZipFile = ZipFile.Read(fileDest)
zip.RemoveEntry(xmlPath)
zip.Save()
zip.AddEntry(xmlPath, customXml)
zip.Save()
End Using
Per the docs for the overload of AddEntry you are using:
The content for the entry is encoded using the default text encoding for the machine
You want this to be UTF-8, so you can use the overload that allows you to specify the encoding:
zip.AddEntry(xmlPath, customXml, Encoding.UTF8);

XML Parsing Error: not well-formed when loading into browser

I am working on a project in visual studio that imports a CSV, and exports an XML file. I'd like to be able be able to get the code to work as XML and HTML, and view it in a browser. I am getting this error when I load the XML file into a browser:
Firefox
XML Parsing Error: not well-formed
Location: file:///C:/Users/fenwky/XmlDoc.xml
Line Number 2, Column 6:<?xsl:stylesheet <abc:stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">?>
Chrome
This page contains the following errors: error on line 2 at column 16: colon are forbidden from PI names 'xsl:transform'
This is what my c# code looks like in visual studio 2013:
// Create a procesing instruction.
XmlProcessingInstruction newPI;
// Stylesheet
String PItext = "<abc:stylesheet xmlns:abc=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">";
newPI = doc.CreateProcessingInstruction("abc:stylesheet", PItext);
doc.InsertAfter(newPI, doc.FirstChild);
// Save document
doc.Save(xmlfilename);
If you are trying to insert an processing instruction into the XML, the data parameter of the CreateProcessingInstruction method does not need to contain the name of the processing instruction in this case. In other words you just need to do this...
var PItext = "xmlns:abc=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"";
var newPI = doc.CreateProcessingInstruction("abc:stylesheet", PItext);
doc.InsertAfter(newPI, doc.FirstChild);
However, I am wondering why you are trying to add this particular processing instruction to an XML document. Perhaps you mean to link an XML document to a separate XSLT document, so it will be transformed if read by a browser?
If so, you probably need to be doing this...
var piText = "type=\"text/xsl\" href=\"style1.xsl\"";
var newPI = doc.CreateProcessingInstruction("xml-stylesheet", piText);
doc.InsertAfter(newPI, doc.FirstChild);
This will write the following processing instruction to the XML, which can then be read by the browser:
<?xml-stylesheet type="text/xsl" href="style1.xsl"?>

How to search through XML to find bad nodes

I have a large XML file (68Mb), I am using SQL Server Business Intelligence Studio 2008 to extract the XML data into a database. There is an error in the XML file some where that prevents it from executing. Possibly a missing tag or something like that. The file is so large I cant manually sort through it looking for the error.
Below is a sample of the the XML schema used.
How can I use XPath to sort through the XML in VS 2012 using C#?
An example would be great!
-<PhoneNumberList>
<PhoneNumber value="1234567890" type="Phone"/>
</PhoneNumberList>
-<YearsOfServiceList>
<YearsOfService experienceInMonths="24" description="SuperAdmin" objectCode="049"/>
</YearsOfServiceList>
</Person>
-<Person dob="1960-01-09T00:00:00" lastName="Smith" middleName="Will" firstName="John" id="9999-9999-9999">
-<SiteList>
-<Site id="2014" siteLongName="HA" siteCode="1255" systemCode="999">
-<StaffPositionList>
<StaffPosition id="73" staffPosition="Administrator"/>
</StaffPositionList>
</Site>
</SiteList>
-<ProgramList>
<Program id="1234" siteLongName="ABC" siteCode="0000" systemCode="205"/>
<Program id="5678" siteLongName="DEF" siteCode="0000" systemCode="357"/>
</ProgramList>
-<TypeList>
<Type Description="Leader" certificateType="D"/>
<Type Description="Professional" certificateType="P"/>
</TypeList>
-<EmailList>
<Email value="jsmith#somesite.com" type="Email"/>
</EmailList>
-<PhoneNumberList>
<PhoneNumber value="1234567890" type="Phone"/>
</PhoneNumberList>
-<YearsOfServiceList>
<YearsOfService experienceInMonths="24" description="SuperAdmin" objectCode="049"/>
</YearsOfServiceList>
</Person>
</PersonList>
</GetPersonDetail>
If you want to do it in code then create an XSD file describing a valid format for the data, embed it as a resource in your app and then use code like this
var errors = new List<string>();
var schemaSet = new XmlSchemaSet();
schemaSet.Add("", XmlReader.Create(new StringReader(Properties.Resources.NameOfXSDResource)));
document.Validate(schemaSet, (sender, args) =>
{
errors.Add(args.Message);
}
);
This will give you a list of validation errors.
You don't need to search "by hand" if you use a competent text editor. NotePad++'s XML plugin, for instance, can determine if your XML as a whole is well-formed or valid, and both instances will provide separate error messages.
If you don't have a schema and the file is well-formed, you can use the CLR's System.XML namespace to read in the document and then iterate through its nodes using LINQ-to-XML, which would allow you to very finely control which nodes go where. With LINQ, you could either create a new XML file with only the valid entries, procedurally correct the invalid entries as you determine where they are, or even just write to your SQL server database directly.
Your troubleshooting process should be something as follows:
Is the XML well-formed? I..e, does it comport to the fundamental rules of XML?
Is the XML valid? I.e., does it have the elements and attributes you expect?
Is your import query accurate?
For things like this I usually have luck checking and fixing the data in Notepad++. Install the XmlTools plugin and that has a menu for checking the xml syntax and tags.
Also, those dashes will give you problems, it's best to save out the xml file directly without copying by hand.
A 68MB XML file is no problem for XML editors such as XMLBlueprint 64-bit (http://www.xmlblueprint.com/) or Stylus Studio (http://www.stylusstudio.com/). Just check the well-formedness of your xml file (F7 in XMLBlueprint) and the editor will display the errors.

Referencing external xml file through DTD Entity

Is there a way of returning an xml file from a REST webservice. I want to be able to call the server, dynamically create the file and return as if I'd simply returned the xml file as stored on disk.
I've managed to get fairly close by returning an XMLElement:
public XmlElement Airports()
{
//Dynamically build up and return
}
But when I referenced the location from a DTD it doesn't seem to behave in the same way e.g.
This works:
ENTITY XmlFile SYSTEM "http://localhost:59736/MyXmlFile.xml"
But this doesn't
ENTITY XmlFile SYSTEM "http://localhost:59736/MyService.svc/MyMethod"
There must be some subtle difference in the headers or something...
I assume your are not returning a file name or anything like that but the file contents as an XML response. In that case it really is no different if you return the contents of an existing file or generate the contents on the fly.

Categories