In a c# program using interop.qbfc12, the following code:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="12.0"?>
<QBXML>
<QBXMLMsgsRq onError = "continueOnError">
<DepositModRq requestID = "0">
<DepositMod>
<TxnID>B2864-1388784731</TxnID>
<EditSequence>1388784731</EditSequence>
<TxnDate>2014-01-03</TxnDate>
<DepositToAccountRef>
<FullName>Checking Acct-CCFCSB</FullName>
</DepositToAccountRef>
<Memo>Test deposit memo for 01032014-1</Memo>
<DepositLineMod>
<TxnLineID>B2866-1388784731</TxnLineID>
</DepositLineMod>
<DepositLineMod>
<TxnLineID>B2867-1388784731</TxnLineID>
</DepositLineMod>
</DepositMod>
</DepositModRq>
</QBXMLMsgsRq>
</QBXML>
produces this error:
DepositMod
DepositLineModList:
element(1) - ORDepositLineMod: required field is missing
End of DepositLineModList
End of DepositMod
When I use the same code in a vba project using qbfc12 type library, I get no error.
Does the interop library differ from the qbfc library? What must I do to resolve this error.
You might need to look at the XML being generated by the QBFC12 library to see what the difference is.
You are giving DepositLineMod's, but what are you modifying?
Related
I am using the Schematron.net nuget package to validate some XML but I can't figure out how to use the diagnostic tag correctly. I have the following XML:
<bk:books xmlns:bk="http://www.example.com/books">
<bk:book publisher="QUE">
<bk:title>XML By Example</bk:title>
<!--<bk:author>Benoit Marchal</bk:author>-->
<bk:publication-date>1999-12-31</bk:publication-date>
<bk:retailPrice>9.95</bk:retailPrice>
</bk:book>
<bk:book publisher="Addison Wesley">
<bk:title>Essential C++</bk:title>
<bk:author>Stanley Lippman</bk:author>
<bk:publication-date>2000-10-31</bk:publication-date>
<bk:retailPrice>29.95</bk:retailPrice>
</bk:book>
</bk:books>
And my simplified Schematron schema looks like this:
<schema xmlns="http://www.ascc.net/xml/schematron"
schemaVersion="1.01" >
<title>A Schema for Books</title>
<ns prefix="bk" uri="http://www.example.com/books" />
<pattern id="authorTests">
<rule context="bk:book">
<assert test="count(bk:author)!= 0" diagnostics="bookTest">
A book must have at least one author
</assert>
</rule>
</pattern>
<diagnostics>
<diagnostic id="bookTest">
The book that has no author is <value-of select="bk:title"></value-of>
</diagnostic>
</diagnostics>
</schema>
The code I'm running to exercise this schema looks like this:
try
{
var bookValidator = new Validator();
bookValidator.AddSchema("book.xsd");
bookValidator.Validate("book.xml");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
When this runs I get the following console output:
Results from Schematron validation: A Schema for Books
From pattern ""
Assert fails: A book must have at least one author
At: /bk:bk:books[1]/bk:bk:book[1]
<bk:book publisher="QUE">...</bk:book>
(Line: 3, Column: 4)
xmlns:bk="http://www.example.com/books"
Why don't I see the output from the diagnostic tag in my console?
It seems as if the NMatrix.Schematron implementation doesn't support the full set of Schematron features. After looking at the source code I can't find any reference to the diagnostics elements at all. In addition the code seems to only support XPath 1.0 and the earlier implementations of Schematron (before the namespace was changed with ISO standardisation). Best advice is to implement a Schematron pipeline using the Schematron "Skeleton" implementation as a guide, which can be found here: http://schematron.com/front-page/the-schematron-skeleton-implementation/
I'm using the Simple.Data ORM to hook up a database from within the Visual Studio environment that's defined in a local sql file (named convertcsv.sql). I'm following the instructions detailed here, and thus far, I've installed Simple.Data.SqlServer and Simple.Data.Ado via NuGet, have the following in my App XML file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="Simple.Data.Properties.Settings.DefaultConnectionString"
connectionString="convertcsv" />
</connectionStrings>
I have the following in my Program.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Simple.Data;
namespace DatabaseWalkthrough{
class Program{
static void Main(string[] args){
var db = Database.Open();
var tmp = db.mytable.FindAll(db.mytable.NC == 505);
foreach (var d in tmp){
Console.WriteLine(d.NC);
Console.ReadKey();
}
}
}
}
NOTE: In the convertcsv.sql file, there is only one table (mytable) and NC is one of its well-defined fields containing integral values.
At the line where the foreach loop is initialized, the debugger alerts the following error:
Additional information: Format of the initialization string does not conform to specification starting at index 0.
A little bit of sleuthing reveals this Stack Overflow question a similar problem, but that particular instance of the error appears to have been caused by improper credentials to access a database on a server, whereas I'm trying to propagate a database into my C# app in Visual Studio to update it.
I have the following hypotheses for why this could be an issue:
1) The App config XML file cannot locate the convertcsv.sql file. Somewhat unlikely since I preemptively added this file into all of the project subdirectories.
2) Missing parameters - this is possible since I've seen some variation for how DB connections are arranged in the App config file, but the Simple.Data documentation is somewhat translucent.
Any other ideas?
Having issues getting node values. Not sure why the following code is failing to do so.
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='STIG_unclass.xsl'?>
<Benchmark xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cpe="http://cpe.mitre.org/language/2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" id="Windows_7_STIG" xml:lang="en" xsi:schemaLocation="http://checklists.nist.gov/xccdf/1.1 http://nvd.nist.gov/schema/xccdf-1.1.4.xsd http://cpe.mitre.org/dictionary/2.0 http://cpe.mitre.org/files/cpe-dictionary_2.1.xsd" xmlns="http://checklists.nist.gov/xccdf/1.1">
<status date="2015-06-16">accepted</status>
<title>Windows 7 Security Technical Implementation Guide</title>
<description>
The Windows 7 Security Technical Implementation Guide (STIG) is published as a tool to improve the security of Department of Defense (DoD) information systems. The requirements were developed from DoD consensus, as well as the Windows 7 Security Guide and security templates published by Microsoft Corporation. Comments or proposed revisions to this document should be sent via e-mail to the following address: disa.stig_spt#mail.mil.
</description>
<notice id="terms-of-use" xml:lang="en">Developed_by_DISA_for_the_DoD</notice>
<reference href="http://iase.disa.mil">
<dc:publisher>DISA, Field Security Operations</dc:publisher>
<dc:source>STIG.DOD.MIL</dc:source>
</reference>
<plain-text id="release-info">Release: 20 Benchmark Date: 24 Jul 2015</plain-text>
</Benchmark>
Sample XML File.
and the following is my code.
String Title = LoadedXML.Element("Benchmark").Attribute("id").Value;
var XMLData = LoadedXML.Element("Benchmark").Elements("plain-text")
.Single(release => release.Attribute("id").Value == "release-info").Value;
is there a way I can get multiple Node values at the same time? Like getting the Title and Release Value at once instead of having a separate one for each?
Your code is failing because your XML contains Namespace and you can't access your nodes directly. If you want to confirm this simply query LoadedXML.Elements() and examine the values in debugger, you can clearly see the namespaces there:-
So, You need to declare the namespace and use it:-
XNamespace ns = "http://checklists.nist.gov/xccdf/1.1";
If you want both vales to be fetched at once you can project it to a anonymous type like this:-
var result = LoadedXML.Root.Elements(ns + "plain-text")
.Where(x => (string)x.Attribute("id") == "release-info")
.Select(x => new
{
Title = (string)x.Document.Root.Attribute("id"),
XMLData = x.Value
}).FirstOrDefault();
This query is giving me below output:-
Linq-to-xml is generally used to query a XML to filter it's nodes and then get the desired element/values per need. It's more like querying a table with SQL.
If all/most of the XML is required as a result, then the better approach would be to deseralize the XMl into a native (C# here) object and map it to the required model object. XML can always be thought of a serialized version of an object (although it can be manually as well), and can be deserialized back to the actual object.
.Net has native support for all these, see msdn links for XML Serialization and Deserialization for details. You can write a small method to deserialize your object like this.
using System.Xml.Linq;
using System.Xml.Serialization;
public class XMLHelper
{
public T DeserializeData<T>(string data)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
StringReader reader = new StringReader(data);
var deserializedObject = serializer.Deserialize(reader);
return deserializedObject == null ? default(T) : (T)deserializedObject;
}
}
To get the string you can do like File.ReadAllText(xmlFilePath) or whatever is easier for the situation.
This will give you deseialized object of the whole XML. If you want some other transformed object, you can either manually map that, or use AutoMapper
By using include tag I am trying to put comments for my code in separate file "docs.xml".
But it does not work. I have been trying both C# and VB.NET projects.
Here is my comments file:
<?xml version="1.0" encoding="utf-8" ?>
<d>
<summary>Demo summary</summary>
</d>
I have a class ABC with one single property Demo. before this property I write:
/// <include file="docs.xml" path="d/*" />
or in VB.NET:
''' <include file="docs.xml" path="d/*" />
However summary for ABC.Demo never appears in InteliSense / Object browser / another project (if I reference my project).
I have a strong feeling I am missing something here.
P.S. I have tried following "path[#name=]" pattern of XML file, but it does not help.
Perhaps you already saw this in the documentation then, but if I understand correctly, you have to do the following:
In Visual Studio, you specify the XML doc comments option in the Build
pane of the Project Designer. When the C# compiler sees the
tag, it will search for documentation comments in xml_include_tag.doc
instead of the current source file.
I have a working C# COM component dll, with a class called MyComponent in the ap namespace, which is added to the GAC and registered successfully. I added a Add() call to it, tested it with a win32 c++ exe and called the Add() call successfully, so its all working.
However I want to test the call in WSF (windows script) I put the code below in a file called test.wsf, when I run the code I get an error:
Error: Could not connect object, on the line:
WScript.ConnectObject(appos,"ap_");
Why is it not connecting! Help!
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/WindowsScriptHost">
<job>
<?job debug="true" ?>
<script language="JScript">
<![CDATA[
// Create action provider
var appos = WScript.CreateObject ("ap.MyComponent");
WScript.ConnectObject (appos, "ap_");
// Initialise voucher provider with store and terminal id strings
appos.Add(1,99);
// Release object
appos = null;
WScript.StdIn.Read(1);
]]>
</script>
</job>
</package>
From MSDN:
Connects the object's event sources to functions with a given prefix.
http://msdn.microsoft.com/en-us/library/ccxe1xe6(VS.85).aspx
This Methods registers for callbacks. If you do not have callbacks, you don't need to call this method.
Sorry, my answer was not precice enough.
WScript.ConnectObject (appos, "ap_");
This method is for attaching your script to the COM Objects events. You have no events, so you don't need to call that method.
From MSDN:
Connects the object's event sources to functions with a given prefix.
http://msdn.microsoft.com/en-us/library/ccxe1xe6%28VS.85%29.aspx
This should be enough:
// Create action provider
var appos = WScript.CreateObject ("ap.MyComponent");
// Initialise voucher provider with store and terminal id strings
appos.Add(1,99);