Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

Covert a document with Qualified elements to Unqualified Elements

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ravi Shankar - 09 Mar 2008 06:56 GMT
Hi,

What kind of XML jugglery will permit me to covert a XML Document with
"Qualified" elements into an XML document without Qualified Elements.

eg: The source document is something like

<ns0:baseelement xmlns:"http://schemas.myorg.com/solutions/yabadaba">
   <ns0:record1>
       <ns0:nelement1>value</ns0:nelement1>
       ...
       ...
   </ns0:record1>
   ...
   ...
</ns0:baseelement>

to something like

<baseelement xmlns:"http://schemas.myorg.com/solutions/yabadaba">
   <record1>
       <nelement1>value</nelement1>
       ...
       ...
   <record1>
   ...
   ...
</baseelement>

Regards,
Ravi Shankar
Martin Honnen - 09 Mar 2008 13:03 GMT
> What kind of XML jugglery will permit me to covert a XML Document with
> "Qualified" elements into an XML document without Qualified Elements.
>
> eg: The source document is something like
>
> <ns0:baseelement xmlns:"http://schemas.myorg.com/solutions/yabadaba">
                   ^^^^^^^
That is not proper XML syntax, I think you want
xmlns:ns0="http://schemas.myorg.com/solutions/yabadaba".

>     <ns0:record1>
>         <ns0:nelement1>value</ns0:nelement1>
[quoted text clipped - 8 lines]
>
> <baseelement xmlns:"http://schemas.myorg.com/solutions/yabadaba">
               ^^^^^^^
That isn't proper XML syntax either. I think you want
xmlns="http://schemas.myorg.com/solutions/yabadaba".

>     <record1>
>         <nelement1>value</nelement1>
[quoted text clipped - 4 lines]
>     ...
> </baseelement>

An XSLT stylesheet could do the job:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="*">
    <xsl:element name="{local-name()}" namespace="{namespace-uri()}">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@* | text() | comment() | processing-instruction()">
    <xsl:copy/>
  </xsl:template>

</xsl:stylesheet>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Ravi Shankar - 09 Mar 2008 18:25 GMT
Hello Martin,

Thank you for the quick response.
The output I've mentioned I get as a result of XML De-serialization.

I've a schema for which I used XSD to generate classes and compiled them
into a DLL. In BizTalk I then use the schea to define a message and use the
classes to help me manipulate various components of the message within the
BizTalk orchestration...

Now I ran into a situation where I need to pass this deserialized object as
a parameter to a ASP.Net WebService and get the response back which was not
working and while debugging I found that while I had a quialified element
message I needed to generate a message which has unqualified elements.

Your response with XSL is an option I could possibly use within an external
.Net component I could call from the orchestration as a helper function.

Thanks & Regards,
Ravi Shankar

> > What kind of XML jugglery will permit me to covert a XML Document with
> > "Qualified" elements into an XML document without Qualified Elements.
[quoted text clipped - 48 lines]
>
> </xsl:stylesheet>
Martin Honnen - 09 Mar 2008 18:36 GMT
> I've a schema for which I used XSD to generate classes and compiled them
> into a DLL. In BizTalk I then use the schea to define a message and use the
[quoted text clipped - 5 lines]
> working and while debugging I found that while I had a quialified element
> message I needed to generate a message which has unqualified elements.

Whether an element is marked up as
  <foo xmlns="http://example.com/2008/ex1"></foo>
or as
  <pf1:foo xmlns:pf1="http://example.com/2008/ex1"></pf1:foo>
should not matter to a web service.

As you are using XML serialization/deserialization you might also want
to have a look at
<URL:http://msdn2.microsoft.com/en-us/library/ms163161.aspx> as there
you can provide a third parameter mapping namespace URIs to prefixes.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Ravi Shankar - 13 Mar 2008 08:48 GMT
Hi Martin,

Thank you for the reference.
The problem has been resolved. The schema that we were working with has
basic definition  issues. Once we sorted those out, the resultant classes
generated by XSD worked fine.

I cannot control the serialization/deserialization as this is done by the
SOAP adapter that comes with BizTalk.. All I can ensure is that the message
is passed with correct data.

Thanks & Regards,
Signature

Ravi Shankar

> > I've a schema for which I used XSD to generate classes and compiled them
> > into a DLL. In BizTalk I then use the schea to define a message and use the
[quoted text clipped - 16 lines]
> <URL:http://msdn2.microsoft.com/en-us/library/ms163161.aspx> as there
> you can provide a third parameter mapping namespace URIs to prefixes.
Martin Honnen - 09 Mar 2008 16:00 GMT
> What kind of XML jugglery will permit me to covert a XML Document with
> "Qualified" elements into an XML document without Qualified Elements.

Here is how you could solve that with LINQ to XML in the .NET framework 3.5:

            XDocument doc = XDocument.Load(@"XMLFile1.xml");
            foreach (XAttribute att in
doc.Descendants().Attributes().Where(a => a.Name.Namespace ==
XNamespace.Xmlns).ToList())
            {
                att.Remove();
            }
            doc.Save(@"XMLFile2.xml");

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.