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
Related
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?).
In my project, there are multiple xml files. Main xml files contains references of other xml files and so on using Attribute.
Sample XML
A.XML
<AList>
<A Id="1"><Name>A</Name></A>......
</AList>
Id = 1 means read data from B.xml contaijg Id = 1.
B.xml
<BList>
<B Id="1"><Name>A</Name></B>......
</BList>
There are around 20 XMl files and these are very complex files. I want to search each and every xml file to find out proper values.
Approach 1
Using XDocument, I am loading all these xml and then using XDoucment I am reading values using Descendent property and sending data back to service.
Approach 2
Write domain model, class containing get and set properties prepared for this. In case of domain model, I have to serialize each and every XML, then using for loop, I have search for right data. Then I have to send this data back to some service.
Which approach is better ?
If all your application does is searching data in xml and sending that xml to some service, then there is no need for domain model.
If you have complex business rules, and much more logic, than simply sending xml you have found, then consider to create domain model. In that case you don't need to serialize domain classes into xml to perform search - search will occur on domain entities level (e.g. with some domain service).
The project I'm working on is an Extranet. I need to call a webservice in this project that communicates with the database. This works as an APPserver.
The procedures between the APPserver and the database are written in Progress. The output that I receive from the webservice is an object that contains XML.
Is it possible to convert the XML file to objects? For example, I have a node
<user>
<uid></uid>
<lastname></lastname>
<firstname></firstname>
</user>
Can this user node convert to a User entity?
The complexity is much higher when it starts with relationships. How the XML will look like, I can't really say at this time.
Are there any other possible frameworks / languages I could use, so they simplify this process?
What will happen with the structure of the relationships and how to handle them?
This example is from an old version of .NET, but it is still relevant. Use XML deserialization to load objects based on an XML format. You can have nested classes. Just decorate all classes/properties as necessary to create the proper format when the object is serialized, and you'll be able to deserialize XML into objects back at the webservice.
http://www.codeproject.com/Articles/4491/Load-and-save-objects-to-XML-using-serialization
Possible Duplicate:
Programmatically Create XML File From XSD
XML instance generation from XML schema (xsd)
How to generate sample XML documents from their DTD or XSD?
Here's the scenario: I've created an application that hooks into a commercial CRM product using their web service API, which unfortunately has a different schema for every installation, based on how the users create their custom fields. This schema can also be modified at any time. This application will be installed at the customer location, and will need to function even when they change their field structure.
In order to insert or update a record, I first call their Project.GetSchema() method, which returns the XSD file based on the current set of fields, and then I can call the Project.AddProject() method, passing in an XML file containing the project data.
My question is: What's the best way to generate the XML from the XSD file at runtime? I need to be able to check for the existence of fields, and fill them out only if they exist (for instance, if the customer deleted or renamed some fields).
I really don't want to have the application attempting to recompile classes on the fly using xsd.exe. There simply must be a better way.
[update] My current solution, that I'm working on, is to basically parse out the XSD file myself, since the majority of the schema is going to be the same for each installation. It's just an ugly solution, and I was hoping there was a better way. The biggest problem I have is that their schema uses xsd:sequence, so putting things in a different order always breaks validation.
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.