c# XPath Navigator Select statement fails due to misinterpretation of token - xpathnavigator

When attempting to return the value associated with any of the “Qx_x” when the http:// address is loaded to Q91_1, the Navigator fails as it interprets the “Id” in “ProjectId” as a valid token - even though the intent is to only pickup "f id=" . Is there a way to alter the expression created to prevent the Navigator from not functioning correctly?
public string GetResponsesValue(string fieldHeading) {
// Use XPath to get the response value.
string expr = string.Format("/Fields/f[#id=\"{0}\"]", fieldHeading);
XPathNodeIterator xpni = Navigator.Select(expr);
return xpni.MoveNext() ? xpni.Current.Value : null;
}
// Cached XPathNavigator
private XPathNavigator xpn;
private XPathNavigator Navigator {
get {
if (xpn == null) {
XPathDocument xpd = new XPathDocument(new StringReader(SurveyResponses));
xpn = xpd.CreateNavigator();
}
return xpn;
}
}
The data in “SurveyResponses” referenced above in StringReader is represented below.
DataResponse XML structure appears as follows (start end arrows removed to allow entry here
Fields
f id="Q21_1">30121 /f
f id="Q91_1">http://xxx.yyy.net/run.aspx?GroupId=188&ProjectId=1096&RecordId=634 /f
f id="Q48_3">22101 /f
/Fields
The code works fine as long as the string containing the URL isn't included in the XML.

Related

TinyTree.getNamespaceBindings() failing

We have upgraded from Saxon EE 9 to 10.1. The following line of code:
private void declareNameSpaces(XdmNode xmlRootNode, XPathCompiler xPath) {
NamespaceBinding[] namespaceBindings = ((TinyDocumentImpl) xmlRootNode.getUnderlyingValue()).getTree().getNamespaceBindings();
Throws the exception:
Caused by: java.lang.UnsupportedOperationException
at net.sf.saxon.tree.tiny.TinyTree.getNamespaceBindings(TinyTree.java:1642)
at net.windward.datasource.xml.SaxonDataSource.declareNameSpaces(SaxonDataSource.java:395)
What do we need to do differently?
The entire code in case you need it is:
private void declareNameSpaces(XdmNode xmlRootNode, XPathCompiler xPath) {
NamespaceBinding[] namespaceBindings = ((TinyDocumentImpl) xmlRootNode.getUnderlyingValue()).getTree().getNamespaceBindings();
List<String> prefixes = new ArrayList<String>();
for (NamespaceBinding namespaceBinding : namespaceBindings) {
if (namespaceBinding == null)
break;
String prefix = namespaceBinding.getPrefix();
if (prefix == null || prefix.isEmpty()) {//use default prefix if prefix is empty.
prefix = defaultPrefix;
// make sure the prefix is unique
while (prefixes.contains(prefix)) {
if (Character.isDigit(prefix.charAt(prefix.length() - 1)))
prefix = prefix.substring(0, prefix.length() - 1) + String.valueOf((int) prefix.charAt(prefix.length() - 1) + 1);
else
prefix = prefix + '1';
}
prefixes.add(prefix);
}
String uri = namespaceBinding.getURI();
if (uri != null && !uri.isEmpty()) {
xPath.declareNamespace(prefix, namespaceBinding.getURI());
prefixNamespaceMap.put(prefix, namespaceBinding);
uriToPrifixeMap.put(namespaceBinding.getURI(), prefix);
}
}
}
You're using what we class as "system programming interfaces" here, which are subject to change from one major release to another. The whole area of namespace representation on the NodeInfo interface changed significantly in 10.0 - see the "changes" section of the documentation for more detail. The model is now closer to the XDM spec, revealing only the in-scope namespaces for a node, and not the "declarations" (i.e. differences from a parent node).
I can't really tell what your code is trying to achieve, especially as it seems to be looking at the namespace bindings for a document node, which will always be empty.
In general with 10.0 you should get namespace information using NamespaceMap getAllNamespaces();

IronResponse calls an JsObjectImpl object, but I cant find class docs on it

I was trying to parse the return of an IronAjax success handler and set the response to an instance of Map. It seems to not like that.
My HTML Markup is:
<iron-ajax id="myAjaxId" auto
url="http://localhost:12345/test_server/v1/daily"
handle-as="json"
on-response="handleResponse" on-error="handleError"></iron-ajax>
My Dart Code is:
void handleResponse(CustomEventWrapper cew, IronRequest ir){
print("inside handleResponse");
var data = ir.response; // <-- is type JsObjectImpl
print("data");
print(data);
if (data == null) return;
print ("About to set rows");
List<Map> rows = data.containsKey("data") ? data["data"] : [];
print("Variables are Set locally");
$['myDatagrid'].render();
}
#reflectable
String camelToFormal (String input){
String out;
RegExp regex = new RegExp("([A-Z])");
out = input[0].toUpperCase() + input.substring(1).replaceAllMapped(regex, (Match m) => " ${m[1]}");
return out;
}
#reflectable
void handleError(CustomEventWrapper cew, IronRequest ir){
print("____Error:____");
print(ir.response);
}
The Error I get is:
type 'JsObjectImpl' is not a subtype of type 'Map' of 'other'.
I wasnt sure if I need to run convert over it, even though the return type set by IronAjax was json
So, since ir.response will either be set or null, i check if it is null first. the var data line in responseHandler currently sets is, but i have also attempted to do something like: Map data = new Map.from(ir.response); which fails as well.
Even though this is said to be handled as JSON, and is returning a jslint confirmed objected, it seems to have issues to convert it to a proper map instance.
According to Polymer IronRequest at: https://elements.polymer-project.org/elements/iron-ajax?active=iron-request
it says that responseis *, the parsed response body. Am I mistaken as to how this is properly set up, or am I missing something?
You could try Object instead of map on the property and then use convertToDart. Not sure this results in a Map but worth a try I guess. See also Polymer 1.0 - iron-list - selection

Swashbuckle custom string comparer not applied for order groups of actions

In Swashbuckle there is a setting called OrderActionGroupsBy which is supposed to change the ordering within the API, but nothing I do is working and I'm can't determine whether this is a Swashbuckle problem, or due to my IComparer any idea what I'm doing wrong?
This is setting the configurations
config.EnableSwagger(c =>
{
...
c.OrderActionGroupsBy(new CustomStringComparer());
c.GroupActionsBy(apiDesc => GroupBy(apiDesc));
...
}
This is grouping the actions by type instead of controllerName.
private static string GroupBy(ApiDescription apiDesc)
{
var controllerName = apiDesc.ActionDescriptor.ControllerDescriptor.ControllerName;
var path = apiDesc.RelativePath;
if (controllerName.Contains("Original"))
{
controllerName = controllerName.Replace("Original", "");
}
// Check if it is one of the entities if so group by that
// Otherwise group by controller
var entities = new List<string>() { "Users", "Apps", "Groups" };
var e = entities.Where(x => attr.Contains(x.ToLower())).FirstOrDefault();
if (e != null)
{
return e;
}
return controllerName;
}
This is my attempt at an IComparer I want Users first and then after that alphabetical
class CustomStringComparer : IComparer<string>
{
public int Compare(string x, string y)
{
if (x.CompareTo(y) == 0)
return 0;
if (x.CompareTo("Users") == 0)
return -1;
if (y.CompareTo("Users") == 0)
return 1;
return x.CompareTo(y);
}
}
}
This isn't working it always defaults to alphabetical no matter what I do.
Looks like this is a bug with Swashbuckle/Swagger-ui
Using OrderActionGroupsBy is correctly sorting the JSON file, but then swagger ui automatically resorts this to alphabetical order.
I have filed bugs with both Swashbuckle and swagger-ui since this seems to go against what is said in swagger-ui's doc regarding apisSorter.
Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or
a function (see Array.prototype.sort() to know how sort function
works). Default is the order returned by the server unchanged.
Swashbuckle issue
swagger-ui issue
swagger-ui specific stackoverflow question

How do I display links from all modules (opened or closed) in DOORS DXL?

I'm writing a DXL script that is following links through multiple levels. I've noticed that the script correctly iterates through these links when the modules are open. However, there are approximately 20 modules to iterate through and I don't want to open all of these modules. How do I view these links without having to manually open the linked modules?
Here's an example of my code:
// Checks to see if the object exists or not. If not returns a null.
// This will be eventually adapted to make sure the object is from a
// specific set of modules, but for now we're just checking for ability
// to retrieve
Object getObject(Link obj_link) {
ModuleVersion other_ver = null
ModName_ other_mod = null
Object other_obj
other_ver = sourceVersion obj_link
other_mod = module(other_ver)
if (null other_mod || isDeleted other_mod) return null
other_obj = source obj_link
if (null other_obj) load(other_ver, true)
other_obj = source obj_link
if (isDeleted other_obj) return null
return other_obj
}
// Displays the object from a specific link module if it's found
void showOut(Object o) {
Link l_obj_link
string s = null
Item linkModItem = itemFromID(MODULE_ID)
string linkModName = fullName(linkModItem)
for l_obj_link in all(o <- linkModName) do {
Object test_obj
display("Test")
test_obj = getObject(l_obj_link)
if (null test_obj){
display("Null Object Found")
} else {
s = probeRichAttr_(test_obj, "Object Identifier", false)
displayRich(s)
}
}
}
// Call showOut for the object
showOut(obj)
Again, using this as a Layout DXL script I can see the object ID if and only if the linked module is opened.
First of all, I would recommend using the Analysis -> Wizard and be sure to select the option for All Modules instead of All Open Modules to generate all the code for you instead, then modify that code to display what you want if it doesn't give you exactly what you need.
However, if you just want to update your existing code you need to change your getObject function to include opening each module silently (to get the information the module must be open, but it doesn't need to be visible).
Object getObject(Link obj_link) {
ModuleVersion other_ver = null
ModName_ other_mod = null
Object other_obj
other_ver = sourceVersion obj_link
other_mod = module(other_ver)
Module m = read(fullName(other_ver), false) // false, tells it to open silently.
if (null other_mod || isDeleted other_mod) return null
other_obj = source obj_link
if (null other_obj) load(other_ver, true)
other_obj = source obj_link
if (isDeleted other_obj) return null
return other_obj
}
This should work as well but I would still recommend starting with the analysis wizard instead because it would be cleaner.
You need to load the module using the link references (LinkRef). Here's a simple function that loads all the modules for a specific LinkModule and Object:
// Loads all incoming linked modules for the given link module and Object. To load from
// ALL link modules use the linkModName = "*"
void LoadSourceModules(string linkModName, Object o) {
ModName_ otherMod = null
LinkRef lr
// For each incoming link check to see if the moduel exists, isn't deleted and loaded
// if not loaded `(null data(sourceVersion lr))` then load the module.
for lr in all(o<-linkModName) do {
otherMod = module(sourceVersion lr)
if (!null otherMod) {
if ((!isDeleted otherMod) && (null data(sourceVersion lr))) {
load((sourceVersion lr), false)
}
}
}
}

How to filter results in controller operating on getting string from view in MVC5

I have a "video" search box in view that takes string input from user and pass back to controller...
Controller then operates on the string and returns data (Videos Name) to view.
I want to include the ".contain()" function to operate on string which contains the video.
Note: Controller returns exact same result as requested Name.
Code is as follows:
public ActionResult SearchVideos(string str)
{
IQueryable<VideoDM> videodm = db.Video.Where(search => search.Title==str);
if(str != null)
{
return View(videodm);
}
else
{
string err = "No Video Found";
return View(err);
}
}
Is there a way to add contain() function after where() to tell the controller to return the result that contains the string "str"?
Add .contain() inside where clause.
IQueryable<VideoDM> videodm = db.Video.Where(search => search.Title.Contains(str));

Resources