简体   繁体   中英

How to import xml namespaces with multiple URI

I have on class that is using Axis Properties to navigate XElements. In doing so, I have used the import statement to import the xml namespaces. I would like to use the same class to work with different versions of xml files have different URI for the namespaces but the same prefix.

if version 1.0 then

imports <xmlns:name1="urn:company:name1:1.0">
imports <xmlns:name2="urn:company:name2:1.0">
imports <xmlns:gml="http://www.opengis.net/gml/3.2">

if version 2.0 then

imports xmlns:name1="urn:company:name1:2.0"
imports <xmlns:name2="urn:company:name2:2.0">
imports <xmlns:gml="http://www.opengis.net/gml/3.2">


public class myObject
  public Function GetElements(byval inXElement as XElement) as IEnumerable(of XElement)
    dim IXElement = from myElement in inXElement...<name1:ElementName> select myElement 
    return IXElement
  end function
end class

I am sure this can be accomplished by making different objects for each version that inherit from a base class but was hoping for something that would a little quicker and require less duplication of code. Many of the functions and subs of the sub-classes would be exactly the same except for the URIs associated the prefixes. So importing the namespaces in the base class wouldn't work. If I import the namespaces in the sub-classes, then I have to duplicate all the functions and subs.

I couldn't find a solution for dynamically switching which namespaces to import so I redesigned the xml schemas and removed the version number from all the "urn:company:name" namespaces. Obviously this is not ideal because the situation can (and likely will) arise where there will be a need to import different versions of namespaces that I don't have control over ie gml/3.2 vs gml/3.3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM