Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to form poorly formed XML

Status
Not open for further replies.
Apr 10, 2006
5
US
I have a VB.net application that I am pulling a webservice XML, and then reading it into an adapter that will push the records into a Sql Server database with the same schema as the database table it is writing to. My code works on well formed XML, the only problem is that the XML from this one Webservice does not write the elements that are nulls.

For instance, if element1 = 1, element2 = null and element3 = 3 it looks like this:

<elementtest>
<element1>1</element1>
<element3>3</element3>
</elementtest>
-----------------------------
as opposed to this:

<elementtest>
<element1>1</element1>
<element2></element2>
<element3>3</element3>
</elementtest>
----------------------------

I have a schema in a .xsd file that lists all of the complex types. Is there a way, once the XML file has been pulled from the webservice, to either edit it by filling in the elements that have nulls (as opposed to them just not being there), or to have it validated as it is pulled from the webservice? The problem is that once it tries to write to the database as it is iterating through the XML, if an element is missing, it throws an error bc it thinks element3 is really column number 2 instead of column number 3.

Thanks in advance.
 
First, both of these examples are well-formed. Both examples may, or may not, be schema-valid. Please post the schema.

One could use XSLT to create a document your application thinks is more acceptable. Do you have any control over the coding of the application? If so, perhaps it should be more tolerant...

Tom Morrison
 
The example schema:

<elementtest>
<element1>1</element1>
<element2></element2>
<element3>3</element3>
</elementtest>

is a perfect example of what the schema should look like. I cannot post the schema for the document is classified, hence the use of 'element1' and the like instead of the actual names of the elements.

I do have complete control over the application I am using. I've never used XSLT before though... are you saying that after we pull the xml, to run it through code to populate it based on the schema in an XSLT? Do you have an example of this that I can use to work on?
 
If the document is schema valid, you should change the routine that writes to the database or change the schema to make the elements mandatory.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top