I am working on a "schema" search, where you can write some part of the xpath and after that, system should show you what are the further possibilities of the node (so what other node can be accessed after specific node). However, I am looking for some solution which would create me a list of possible parents and childs based on the schema.
It's complicated of course because of wildcards, substitution groups, types derived by extension, model groups, and such details. I would recommend using an API offered by a schema processor rather that trying to analyse the source XSD documents directly. One approach, for example, would be to generate an SCM file from the schema using Saxon. You can then search the SCM file for all the declarations of a particular element name, look up their types, and from the types you can discover the list of allowed child element names. You would probably want to do this by first converting the SCM file to your own data structure geared to your particular needs: as you suggest, this might be a simple list of parent/child element name pairs (plus element/attribute name pairs, perhaps?).
Related
I have a SQL query which returns a large set of fields.
I'd like to ultimately output this to a CSV file / XML file, selecting a specific subset of fields based on some configuration (which itself may reside in SQL, or a config file). The subset may be a list of the field names that apply to this configuration.
Trying to figure out how best to achieve this- I had look at using Automapper, mapping my Result Object (which contains all fields) to a dynamic object containing just the fields I want, but I am unsure if this is performant, or if Automapper can take a list of fields to map from config (say, a List of field names).
I have also considered whether to restrict the results from SQL using Entity Framework, but again am unsure on how to do this.
I'm working on a solution that posts data to a SOAP web service. My sending application has a database table that holds the mappings between that application and the receiving application.
I've generated a class from the XSD using xsd tools. Ideally the solution will then traverse the elements within the xsd/class and if the element name sits in my database table, it will set that elements property accordingly.
First I found this documentation from Microsoft
https://learn.microsoft.com/en-us/dotnet/standard/data/xml/traversing-xml-schemas
But it only finds one level of parent and child
Then I kept digging and found this post on here
Traversing XML Schemas failed
This gives me the same result, so I can only assume its the schema that is the problem?
This is what is looks like, I can't get to "Type" for example
Schema
Currently we have a XML Schema and the code reads the xml file, validates against the schema and save to database. In future there would be schema changes, how can the code handles them without needing to rewrite the code for new schema.
Thanks,
Let me give an example
<Products>
<product id="1">
<name> ABC </name>
<desc> good one </desc>
</product>
</products>
XPath mapping configuration
Table Column XPath
Product id //Products/product/id
Product name //Products/product/name
Product desc //Products/product/desc
Now the C# code reads id, name and desc and generates an insert statement based on the Mapping configuraiton
If the schema changes and new element is added say price and we would add that price to mapping, so the new insert statement that is generated includes price.
Will this work?
I hate parsing XML and loading it into objects. Due to this, you can try the following approach.
Create a C# object that represents the XML data you are talking about. Serialize that C# class, and viola you have an XML schema that is strongly typed. Also, if in the future you need additional schema changes, simply modify the C# class and reserialize and you're all set.
This also removes the need to parse the XML document (assuming you are utilizing it within the CLR), as you can simply reference the C# class and you can deserialize it back into memory without any parsing.
The way of handling something like this that immediately comes to mind would be to have a known good skeletal XML schema with no data in it, have the code parse and learn that schema, and then have it run on whatever arbitrary input you give it. When the XML schema changes, simply have a trusted user/admin go in and change the known good skeleton.
You should make sure your database can handle these changes without any extra prodding, and you should most definitely have at least a few tests that run regularly and throw off alerts if a problem is detected. One of the most dangerous elements in 'low maintenance' processes like these is that they often fail quietly and there's no way to tell they're broken!
I'm a little afraid I'm not getting your whole question because you added a bunch of tags that aren't obviously in your question, but hopefully this helps.
If the location for the XML data changes, unless you want to abstract the crap out of your XML file (include metadata in the document describing where to find things) you're out of luck. If your data elements will always be in the same place, all you have to do is keep your XSD file as a separate file, and change it when necessary to validate the document.
I want to use the powerful DataContractSerializer to write or read data to the XML file.
But as my concept, DataContractSerializer can only read or write data with entire structure or list of structure.
My use case is describe below....I cannot figure out how to optimize the performance by using this API.
I have a structure named "Information" and have a List<Information> with unexpectable number of elements in this list.
User may update or add new element into this list very often.
Per operation (Add or Update), I must serialize all the element in the list to the same XML file.
So, I will write the same data even they are not modified into XML again. It does not make sense but I cannot find any approach to avoid this happened.
Due to the tombstoning mechanism, I must save all the information in 10 secs.
I'm afraid of the performance and maybe make UI lag...
Could I use any workaround to partially update or add a data information into the XML file by DataContractSerializer?
DataContractSerializer can be used to serialize selected items - what you need to do is to come up with scheme to identify changed data and way to efficiently serialize it. For example, one of the way could be
You start by serializing entire list of structures to an file.
Whenever some object is added/updated/removed from list, you create a diff object that will identify kind of change and the object changed. Then you can serialize this object to xml and append the xml to file.
While reading the file, you may have to apply similar logic, first read list and then start applying diffs one after another.
Because you want to continuous append to file, you shouldn't have root element in your file. In other words, the file with diff info will not be an valid xml document. It would contain series of xml fragments. To read it, you have to enclose these fragments in a xml declaration and root element.
You may use some background task to write the entire list periodically to generate valid xml file. At this point, you may discard your diff file. Idea is to mimic transactional system - one data structure to have serialized/saved info and then another structure containing changes (akin to transaction log).
If performance is a concern then using something other than DataContractSerializer.
There is a good comparison of the options at
http://blogs.claritycon.com/kevinmarshall/2010/11/03/wp7-serialization-comparison/
If the size of the list is a concern, you could try breaking it into smaller lists. THe most appropriate way to do this will depend on the data in your list and typical usage/edit/addition patterns.
Depending on the frequency with which the data is changed you could try saving it whenever it is changed. This would remove the need to save it in the time available for deactivation.
If I have thousands of hierarchical records to take from database and generate xml, what will be the best way to do it with a good performance and less CPU utilization?
You can output XML directly from SQL Server 2005 using
FOR XML
The results of a query
are returned as an XML document. Must be used with
one of the three RAW, AUTO
and EXPLICIT options
RAW
Each row in the result set is an XML element with a generic
identifier as the element tag
AUTO
Results returned in a simple
nested XML tree. An element will
be generated for each table field in the
SELECT clause
EXPLICIT
Specifies the shape of the resulting
XML tree explicitly.
A query must be written in a
particular way so that additional
information about the nesting is
specified
XMLDATA
Returns the schema, but does not add the root element to the result
ELEMENTS
Specifies that the columns are
returned as child elements to the table
element. If not specified, they are mapped as
attributes
Generate an inline XSD schema at the same time using
XMLSCHEMA
You can handle null values in records using
XSINIL
You can also return data in Binary form.
You might want to have a look on MSDN for XML support in SQL Server 2005, for technologies such as XQuery, XML data type, etc.
That depends - if your application and database servers are on separate machines, then you need to specify which CPU you want to reduce the load on. If your database is already loaded up, you might be better off doing the XML transform on your application server, otherwise go and ahead and use SQL Server FOR XML capabilities.
Oracle has tools for that, so I guess SQL-Server does too, but you'll need a schema. Personally for small set I use a php script I have around, but for big stuff with need for customization is another story.