Is there a possibility to get the response as the following since in my experience using data contracts does not allow to add an id inside an element (e.g. ). Is there a way to achieve the following structure? Also notice that this is without a root tag.
<Number Id=”1”>
<FName>1234567890ABC</ FName >
<Date>7/1/2012 12:00:00 </ Date >
</Number >
< Number Id=”2”>
< FName >9876543210XYZ</ FName >
< Date >7/1/2012 12:00:00 </ Date >
</ Number >
Thank you very much in advance.
from this post: How can you control .NET DataContract serialization so it uses XML attributes instead of elements?
. . . take a look at XmlSerializerFormatAttribute which allows you to use
the XmlSerializer for serialization.
and from same post
You can do this with the DataContractSerializer - the answer is to take over the Xml serialization yourself by
implementing the IXmlSerializable interface. ...
This article can be also helpful: http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/
Related
I am newbie in RESTful jersey.
I would like to ask what is the different among '#PathParam' Vs '#QueryParam' vs '#MatrixParam' in jersey?.
Can't help you with the #MatrixParam but can give you an answer for the other two:
#PathParam: you use placeholder in the path. For example: #Path("/demo/{id}"). In this case the {id} part is your placeholde which you get with #PathParam("id")
#QueryParam: you use the normal uri query Syntax. For example: google.com?q=searchquery which translates to: #QueryParam("q") in your application
I want to get a xquery transformation drafted for below data.. here as part of service response fault, I am getting below payload and need to capture the data in ErrorCode element.
challenge that I am having here is, this is not part of a XML structure, its coming as part of CDATA tags.
Could you please suggest how I can get this value in a variable same.
Say I am getting this structure as part of $Fault and now need to assign ErrorCode in a new variable $FaultCode
$FaultCode = $Fault/con:details/con1:ErrorResponseDetail/con1:detail/ ********
I am not sure how I can capture this further detail element
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
<con:errorCode>382502</con:errorCode>
<con:reason>eceived an error response</con:reason>
<con:details>
<con1:ErrorResponseDetail xmlns:con1="http://www.bea.com/wli/sb/stages/transform/config">
<con1:detail>
<![CDATA[<Error xmlns="http://servic.abcd.net/V1">
<ErrorCode>DATA_AVAILABILITY</ErrorCode>
<ErrorDescription>{"description":"No Cdata for )"}</ErrorDescription>
</Error>]]></con1:detail>
<con1:http-response-code>404</con1:http-response-code>
</con1:ErrorResponseDetail>
</con:details>
<con:location>
<con:node>TestPPNode</con:node>
<con:pipeline>TestPPNode_request</con:pipeline>
<con:stage>Test Stage</con:stage>
<con:path>request-pipeline</con:path>
</con:location>
</con:fault>
Assuming XQuery 3.1 with the parse-xml function (https://www.w3.org/TR/xpath-functions/#func-parse-xml) you can use
declare namespace con="http://www.bea.com/wli/sb/context";
declare namespace con1="http://www.bea.com/wli/sb/stages/transform/config";
declare namespace V1 = "http://servic.abcd.net/V1";
/con:fault/con:details/con1:ErrorResponseDetail/con1:detail!parse-xml(.)/V1:Error/V1:ErrorCode/data()
to get the string value DATA_AVAILABILITY, see https://xqueryfiddle.liberty-development.net/6qM2e27 for demo.
With XQuery 1 there is not XML parsing which is needed to solve this properly but you can of course try to use string functions to extract the data e.g.
/con:fault/con:details/con1:ErrorResponseDetail/con1:detail/substring-before(substring-after(., '<ErrorCode>'), '</ErrorCode>')
How to get specific content type document count in alfresco share UI using Lucene query?
I have tried to query in alfresco share UI Alfresco Lucene query. but it's only giving first 100 results.
Is there any best way to get only document count by specific content type or document count under specific alfresco site??
Please suggest if there is any other best and useful way.
Thanks in Advance.
The class PatchDAO has a method that returns the number of node with a given type:
/**
* Gets the total number of nodes which match the given Type QName.
*
* #param typeQName the qname to search for
* #return count of nodes that match the typeQName
*/
public long getCountNodesWithTypId(QName typeQName);
where typeQName is, of course, the QName of the type.
This method should return the total count and should be the most efficient.
UPDATE:
If you need the count on a specific site this method is not actually usable.
ResultSet result = searchService.query(, SearchService.LANGUAGE_LUCENE, "+PATH:\"/app:company_home/cm:" + + "/*\"" + " +TYPE:\"" + + "\"" );
You can change the parameters as per your need.
Thanks,
Kintu
Hitting the database directly is a very bad idea, so don't even start getting into that bad habit.
Using the Alfresco foundational Java API would require that the Java class be deployed to the server, which is a pain.
The easiest way to do this is to use OpenCMIS. You can run OpenCMIS code remotely, and you can use its paging result set to page through the query results, see Apache CMIS: Paging query result
We are cleaning up data in our database and a column has XML details inside of it which we want to be able to convert into plain text.
Below is the sample XML in the table column.
<FlowDocument PagePadding="5,5,5,5" Name="RTDocument" AllowDrop="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph>FILE DESTROYED - MAY 21st, 2008</Paragraph>
<Paragraph>todo</Paragraph>
</FlowDocument>
I am using this query, but it is not rendering the desired output due to the presence of Namespace (if I remove the namespace from the XML, I am able to render the output successfully).
SELECT
CAST(CAST(Comments AS XML).query('data(/FlowDocument/Paragraph)') AS VARCHAR(7000)) AS activity
FROM
dbo.Activities
WHERE
ActivityID = 1
Kindly help in this matter.
Thanks
You can also declare your namespace like this:
;WITH xmlnamespaces(DEFAULT 'http://schemas.microsoft.com/winfx/2006/xaml/presentation')
SELECT
CAST(CAST(Comments AS XML).query('data(/FlowDocument/Paragraph)') AS VARCHAR(7000)) AS activity
FROM [dbo].Activities where ActivityID=1
Other options are given here: parsing xml using sql server
You need to use namespace declaration in your Query as per: https://msdn.microsoft.com/en-us/library/ms191474.aspx
so your query portion would look something like:
query('
declare namespace NS="http://schemas.microsoft.com/winfx/2006/xaml/presentation";
data(/NS:FlowDocument/NS:Paragraph)
')
I have 290 Group Policy Backup xml files which I need to enumerate in separate folders.
With each Group Policy backup xml file, I need to query the Policy settings.
Anyone who's looked at a Group Policy xml backup file before would know they're chock-a-block full of Namespace declarations.
I want to know, using Linq to XML, as I query each xml file, how can I dynamically query the XML the Namespace and then append the Namespace into the Linq query for the child nodes/values?
Here are some examples of the xml structure.
<User>
<ExtensionData>
<Extension xmlns:q1="http://www.microsoft.com/GroupPolicy/Settings/Scripts" xsi:type="q1:Scripts">
<q1:Script>
<ExtensionData>
<Extension xmlns:q1="http://www.microsoft.com/GroupPolicy/Settings/IE" xsi:type="q1:InternetExplorerSettings">
<q1:PreferenceMode>true</q1:PreferenceMode>
<ExtensionData>
<Extension xmlns:q2="http://www.microsoft.com/GroupPolicy/Settings/Registry" xsi:type="q2:RegistrySettings">
<q2:Policy>
<q2:Name>Disable changing accessibility settings</q2:Name>
<q2:State>Enabled</q2:State>
<ExtensionData>
<Extension xmlns:q1="http://www.microsoft.com/GroupPolicy/Settings/DriveMaps" xsi:type="q1:DriveMapSettings">
<q1:DriveMapSettings clsid="{8FDDCC1A-0C3C-43cd-A6B4-71A6DF20DA8C}">
My initial code looks like this:
Dim NS As XNamespace = "http://www.microsoft.com/GroupPolicy/Settings"
NodeValue = XDoc.Descendants(NS + NodeName).First().Value
As you can see I'm going to face literally dozens of different Namespaces, at this stage I don't even know what they all are.
My end-task is to trawl through 290 directories, each containing one Group Policy xml backup file. I then need to read the Policy Name from each of the settings contained within the backup file.
Because I don't know what Policy settings each xml flie will contain, I don't know what Namespace(s) I need to use when attempting to read the xml values. Each xml file may even contain multiple namespaces.
How do I dynamically read the Namespace in Linq so I can read the values?
Thanks
Do you care about these namespaces? i.e. Do you distinguish them and do different kind of processing depending on the namespace-uri? If you don't (e.g. you just display something) you can do something like this:
XDoc.Descendants().Where(e => e.Name.LocalName == "Extension")
This should select all Extension elements regardless of the namespace. Alternatively, if you need to query elements using namespaces instead of hardcoding one you could do something like this:
foreach(XElement extensionElement in XDoc.Descendants().Where(e => e.Name.LocalName == "Extension")
{
var ns = extensionElement.Name.NamespaceName;
Console.WriteLine(extensionElement(ns + "DriveMapSettings"));
}
From e In XDoc.Descendants Group By e.Name.Namespace.NamespaceName should find all distinct namespaces, but it is untested.
Here's what I ended up with:
Dim ListOfNamespaces = z.Root.DescendantsAndSelf.Attributes().Where(Function(a) a.IsNamespaceDeclaration).GroupBy(Function(a) If(a.Name.[Namespace] = XNamespace.None, [String].Empty, a.Name.LocalName), Function(a) XNamespace.[Get](a.Value)).ToDictionary(Function(g) g.Key, Function(g) g.First())