NSXMLDocument validateAndReturnError requires network connection? - cocoa

I am trying to validate an XML Schema document against the schema for schemas (http://www.w3.org/2001/XMLSchema) using NSXMLDocument. I've gotten it to work correctly, and assumed that I was validating against a local schema.
However, I discovered that without a network connection, this validation doesn't work. Is there any way to force NSXMLDocument to use a local schema for validation?
The code I have working with a net connection:
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:(NSXMLDocumentValidate | NSXMLNodePreserveAll)
error:&err];
NSXMLElement *rootElement = [xmlDoc rootElement];
NSMutableArray *namespaces = [[rootElement namespaces] mutableCopy];
[namespaces addObject:[NSXMLNode namespaceWithName:#"xsi" stringValue:#"http://www.w3.org/2001/XMLSchema-instance"]];
[rootElement setNamespaces:namespaces];
[rootElement removeAttributeForName:#"xsi:schemaLocation"];
[rootElement addAttribute:[NSXMLNode attributeWithName:#"xsi:schemaLocation" stringValue:[NSString stringWithFormat:#"http://www.w3.org/2001/XMLSchema %#", #"/System/Library/Schemas/XMLSchema.xsd"]]];
BOOL vaildXML = [xmlDoc validateAndReturnError:&err];
The schema tag of the document I'm validating:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:myCompany="http://schema.myCompany.com/SomeSchema"
targetNamespace="http://schema.myCompany.com/SomeSchema">
It seems to be having a problem with the w3.org schema location, but not my company's.
The error I'm seeing
error : No such file or directory
I/O warning : failed to load external entity "http://www.w3.org/2001/xml.xsd"
Error Domain=NSXMLParserErrorDomain Code=1 UserInfo=0x103051c10 "Element '{http://www.w3.org/2001/XMLSchema}import': Failed to locate a schema at location 'http://www.w3.org/2001/xml.xsd'. Skipping the import.
attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration.
attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration.
Any ideas?

Looking at the Apple docs for the NSXMLDTD class suggests that you do have access to catalogs. However, there seems to be very limited support for defining the catalog to be used. Either you can create a catalog at /etc/xml/catalog or set the XML_CATALOG_FILES environment variable.
Once you've got a catalog, you should be able to place an entry into it for the W3 schema along with a local copy. Something like:
<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://www.w3.org/2001/xml.xsd" uri="xml.xsd"/>
<uri name="http://www.w3.org/XML/1998/namespace" uri="xml.xsd"/>
</catalog>
This assumes that you have the catalog and the schema in the same directory.
I can't try this myself (lack of time and rusty Cocoa skills) but it should work. If I remember correctly, NSXML is based on libxml2 which certainly supports catalogs.
The specifications for catalogs themselves can be found on the OASIS website.

Related

Undeclared property when creating a record via Web API In Dynamics CRM Online

I am trying to create an entity in Dynamics CRM online with a custom lookup field. Even after providing the SchemaName(sg_DepartmentalProjectId) as mentioned here 'An undeclared property' when trying to create record via Web API I am still getting the same error.
An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'sg_DepartmentalProjectId' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
Below is my JSON Post
{
"sg_invoicenumber": "SIAIR402742-416805",
"sg_accountnumber": "5400",
"sg_description": "xxxx",
"sg_fy": "20",
"sg_name": "Operational Journal: yyy - 09/20/2019",
"sg_departmentid": "CC10530",
"sg_postingdate": "2019-09-20",
"sg_invoicedate": "2019-09-20",
"sg_checkdate": "2019-09-20",
"sg_paidfulldate": "2019-09-24",
"sg_amount": 5597.4,
"sg_effectivedate": "2019-09-20",
"sg_DepartmentalProjectId#odata.bind":"/sg_departmentalmatters(e9c31cec-deff-e411-80c5-0050569732ae)"
}
Please Download Odata Metadata from the Developer resources & verify the exact casing. Jason Lattimer also confirmed that the bug while investigating the CRM REST builder issue:
I've come to figure out the metadata is in fact not the source of truth - it's the CSDL
I know it's super annoying when this is working different & getting solved by different solutions. Make sure you verify in all these places for the custom lookup attribute.
Microsoft reference: CSDL $metadata document
I had the same problem, but in my case using the schema name didn’t work. I believe it’s because my field is setup as a navigation property to either of two different entities. I found the correct name by pulling the metadata for the entity from the API and looking at the navigation properties. There were two navigation properties defined for this field, one for each target entity, so I had to use the name of the correct one in my payload.
<NavigationProperty
Name="parentcustomerid_account"
Type="mscrm.account"
Nullable="false"
Partner="contact_customer_accounts">
<ReferentialConstraint
Property="_parentcustomerid_value"
ReferencedProperty="accountid" />
</NavigationProperty>
The correct value was parentcustomerid_account above.
I had same issue
JSON:
{
"activityid": "cbf73794-9e42-ec11-8c62-00224815945f",
"subject": "Test 22",
"new_AppointmentTypeId#odata.bind": "new_tasktypes(a97ec3cf-3e1a-ea11-a811-000d3a799417)"
}
Error I was getting:
An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'new_AppointmentTypeId' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
Resolution:
Use Metadata Browser https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/browse-your-metadata?view=op-9-1
Find ReferencingEntityNavigationProperty from Metadata Browser for fields you need it.
Working JSON:
{
"activityid": "cbf73794-9e42-ec11-8c62-00224815945f",
"subject": "Test 22",
"new_AppointmentTypeId_Appointment#odata.bind": "new_tasktypes(a97ec3cf-3e1a-ea11-a811-000d3a799417)"
}

Tomcat Startup exception: Failed to read schema document

This is idp.war deployment on tomcat 7(.69)
Failed to read schema document 'class path:/schema/shibboleth-2.0-services.xsd'
in the trace it suggests some things:
1) could not find the document.
2) the document could not be read.
3) the root element of the document is not <xsd:schema>
I can go into the deployment: idp/WEB-INF/lib/shibboleth-common-1.2.1.jar/schema/ and see all the shibboleth-2.0- .xsd files that the Service.xml file is declaring as schemaLocations
this folder was created by tomcat deployment for tomcat so I don't know why it can't be read, I'm guessing permissions issues wouldn't apply here.
and the root element of the .xsd document is
<schema ... >
so that qualifies as
<xsd:schema>
correct or no?
Two points:
(1) Whether a start-tag with the element-type name schema is effectively the same as one with the element-type name xsd:schema depends on the namespace bindings, which are omitted here. (The start-tag <xsd:schema> cannot occur as the first tag in a namespace-well-formed XML document, so I'm assuming you're paraphrasing, not quoting.)
If the unprefixed schema start-tag makes "http://www.w3.org/2001/XMLSchema" the default namespace, then that is not likely to be your problem. (Hint for the next time you ask a question, though: omitting salient information like namespace bindings makes your question less clear and less likely to get useful responses.)
(2) The error message you quote puts a blank between the strings 'class' and 'path' -- if your reference to the schema document actually does begin "class path:", then that is your problem: Shibboleth's documentation says:
Shibboleth defines a special URL scheme, classpath, which ensures that the schema files are resolved from the classpath.
As a matter of URI syntax, blanks are not allowed in the middle of a scheme name. You will need to start any URI you want to identify in this way with "classpath:/", not "class path:/".

HAPI FHIR Json encoder not handling contained resources

I have a FHIR Device resource that contains a FHIR DeviceComponent resource. I use the following HAPI FHIR code to 'insert' one resource into the other:
protected static void insertResourceInResouce(BaseResource resource, BaseResource resourceToInsert)
{
ContainedDt containedDt = new ContainedDt();
ArrayList<IResource> resourceList = new ArrayList<IResource>();
resourceList.add(resourceToInsert);
containedDt.setContainedResources(resourceList);
resource.setContained(containedDt);
}
According to the Eclipse debugger the insertion works fine. This resource with its insertion is then added to a bundle. When all the work is done the Eclipse debugger shows the resource with the contained resource properly placed in the bundle. However, when generating a JSON string the contained resources are not there. The encoding operation appears as follows:
return fhirContext.newJsonParser().setPrettyPrint(true)
.encodeResourceToString(bundle);
Any ideas what I am doing wrong?
It turns out that one must reference the contained resource from the parent resource using the "#" to prefix the reference. If one does that then the contained resource will be present in the XML and JSON.
Admittedly this requirement makes no sense to me. Why would I include a resource INSIDE another scoping resource if I did not think it was important?

EF6.1 Upgrade Issues: To SQL Server CE file Location and [NotMapped] Properties

I really appreciate any insight anyone can provide.
I've come back to a project that was using the EF6.0 rc preview. After updating the projects EF to 6.1 and updating the SQL Server CE I have two problems.
[UPDATE]
Problems 1 & 2 solved Problem 3 is not.
PROBLEM 3 -
Now with the path set via a connection string as explained above, migrations called via the package manager are not working as its an invalid path. Any ideas anyone?
When I start up the debug process, I get problem 1 and the exceptions crash; but it does create a .sdf file although in the wrong location as explained in problem 2.
1. NOT MAPPED PROPERTY AND UNSUPPORTED BY LINQ ERROR
During the initial creation process I get an exception
List<Equipment> duplicateTags = db.EquipmentReg
.GroupBy(e => e.TagAndLocation)
.Where(g => g.Count() > 1)
.SelectMany(g => g).ToList<Equipment>();
The exception is related to the TagAndLocation. TagAndLocation is defined in the model by
/// <summary>
/// Creates concatenation object that will not be mapped in the database but will be in the
/// Object Relational Mapping (ORM) of the EF model.
/// </summary>
[NotMapped]
public string TagAndLocation { get { return Tag + " (" + Location.Name + ")"; } }
A first chance exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
Additional information: The specified type member 'TagAndLocation' is
not supported in LINQ to Entities. Only initializers, entity members,
and entity navigation properties are supported.
Why is this happening now?
2. CONNECTION STRING NOT APPLYING LOCATION
My connection isn't applying the path properly anymore.
I have it being done by a DbConfiguration class which auto runs, I guess due to its inherited class type. As shown below
class HAIDbJob_EFConfiguration : DbConfiguration
{
public HAIDbJob_EFConfiguration()
{
SetProviderServices(SqlCeProviderServices.ProviderInvariantName, SqlCeProviderServices.Instance);
// Create the connection string programmatically - Setting the filename and path.
SetDefaultConnectionFactory(new System.Data.Entity.Infrastructure.SqlCeConnectionFactory(
"System.Data.SqlServerCe.4.0",
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Databases"),
#"Data Source=" + System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Databases") +
#"\Hazardous_Area_Database_Job.sdf"));
}
}
Instead of creating a file in the runtime location ...\bin\Debug\Databases\Hazardous_Area_Database_Job.sdf, it creates it at
..\bin\Debug\HA_Inspector.HAI_Database.HAI_Job_EF_Model.Hazardous_Area_Database_Job.sdf
Which is the full namespace of the database model... I have tried a few solutions found for other people problems of a slightly different nature, but none of it works. Any ideas would be extremely appreciate.
1: The EF provider attempt to translate TagAndLocation to SQL and fails. You must use LINQ to Objects for this grouping.
2: Why not have a named connectionstring in your app.config, or pass it in the DbContext constructor.
SOLUTION 1
I did a string compare in the group by statement since location has a string member Location.Name.
SOLUTION 2
When I originally wrote this I wanted to dynamically name the database all the time and this is why I wrote the initialiser class.
To get around the problem, I just followed Erik's advice and put a XAML connection string in app.config using "Source=./Databases"..... to get the subfolder.

Black Magic in Grails Data Binding?

As described in http://n4.nabble.com/Grails-Data-Binding-for-One-To-Many-Relationships-with-REST-tp1754571p1754571.html i'm trying to automatically bind my REST data.
I understand now that for one-to-many associations the map that is required for the data binding must have a list of ids of the many side such as:
[propName: propValue, manyAssoc: [1, 2]]
However, I'm getting this exception
Executing action [save] of controller [com.example.DomainName] caused exception: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of com.example.DomainName.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.example.DomainName.id
However, even weirder is the update action that is generated for the controller. There we have the databinding like this:
domainObjectInstance.properties = params['domainObject']
But, and this is the really weird thing, params['domainObject'] is null! It is null because all the domainObject fields are passed directly in the params map itself. If I change the above line to
domainObjectInstance.properties = null
the domainObject is still updated! Why is this happening and more important, how can I bind my incoming XML automatically if it comes in this format (the problem is the one-to-many associations):
<product>
<name>Table</name>
<brand id="1" />
<categories>
<category id="1" />
<category id="2" />
</categories>
</product>
It's not 100% clear from your example - what exactly is the contents of your "params" when you try to bind.
If you don't have "domainObject.xxx=yyy" post parameters defined, then nothing will be in params['domainObject']. Namespacing like that is not necessary in most cases, and required the form fields to use the prefix.
I'm guessing your data is coming in as "xxx=yyy" not "domainObject.xxx=yyy".
Furthermore, I'm not sure that [1,2] for associations is right either. Surely that should be [id:1, id:2] ?

Resources