Given an XML structure like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LandXML date="2014-12-18-06:00" language="English" readOnly="false" time="12:12:16.338-06:00" version="1.0" xsi:schemaLocation="http://ift.tt/1CjiOKC http://ift.tt/1MeQdOw" xmlns="http://ift.tt/1CjiOKC" xmlns:xsi="http://ift.tt/ra1lAU">
<Surfaces>
<Surface OID="SIE" desc="Ground Surface" name="Ground">
<Definition surfType="TIN">
<Pnts>
</Pnts>
<Faces>
</Faces>
</Definition>
<SourceData>
<Boundaries>
<Boundary bndType="outer" edgeTrim="true" name="Outermost bounding edge">
<PntList3D>1.5181307542E7 2125297.27 1713.976 1.5181309121E7 2125348.661 1713.65 1.518131357E7 2125401.188 1713.624 1.5181355394E7 2125953.634 1712.622 1.5181471897E7 2127035.359 1711.076 1.5181474238E7 2127060.368 1711.571 1.5181479644E7 2127074.35 1711.4 1.5181484532E7 2127081.58 1711.23 1.5181486144E7 2127083.79 1711.24 1.5181526576E7 2127114.416 1710.763 1.5181604217E7 2127162.511 1710.742 1.518173257E7 2127220.112 1712.713 1.5182046629E7 2127316.035 1716.328 1.5182350908E7 2127362.323 1709.085 1.518238492E7 2126720.863 1678.373 1.5182383044E7 2126559.786 1663.524 1.518236883E7 2126031.128 1708.884 1.5182353785E7 2125775.21 1680.648 1.5182361822E7 2125348.267 1648.468 1.518235892E7 2125223.263 1646.325 1.518233926E7 2124751.224 1640.587 1.5181441405E7 2125081.466 1700.044 1.518132618E7 2125144.398 1708.546 1.5181317827E7 2125194.92 1712.947 1.5181309366E7 2125246.027 1714.161</PntList3D>
</Boundary>
</Boundaries>
</SourceData>
<Units>
<Imperial angularUnit="decimal degrees" areaUnit="squareFoot" diameterUnit="USSurveyFoot" directionUnit="decimal degrees" flowUnit="cubicFeetSecond" heightUnit="USSurveyFoot" linearUnit="USSurveyFoot" pressureUnit="inHG" temperatureUnit="fahrenheit" velocityUnit="feetPerSecond" volumeUnit="cubicFeet" widthUnit="USSurveyFoot"/>
</Units>
<Project desc="GPS Survey, UTM14 North, Autonomous Base, Geoid 2009, Reedy
</Project>
<Application manufacturer="USDA NRCS" name="Engineering Field Tools" version="3.4.1.2">
<Author createdBy="james.reedy"/>
</Application>
</LandXML>
I want to "move" the Units node "To the top just under LandXML" so it appears above the surfaces node node and I need to move the SourceData Node under surface. Here's the final structure I want:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LandXML date="2014-12-18-06:00" language="English" readOnly="false" time="12:12:16.338-06:00" version="1.0" xsi:schemaLocation="http://ift.tt/1CjiOKC http://ift.tt/1MeQdOw" xmlns="http://ift.tt/1CjiOKC" xmlns:xsi="http://ift.tt/ra1lAU">
<Units>
<Imperial angularUnit="decimal degrees" areaUnit="squareFoot" diameterUnit="USSurveyFoot" directionUnit="decimal degrees" flowUnit="cubicFeetSecond" heightUnit="USSurveyFoot" linearUnit="USSurveyFoot" pressureUnit="inHG" temperatureUnit="fahrenheit" velocityUnit="feetPerSecond" volumeUnit="cubicFeet" widthUnit="USSurveyFoot"/>
</Units>
<Surfaces>
<Surface OID="SIE" desc="Ground Surface" name="Ground">
<SourceData>
<Boundaries>
<Boundary bndType="outer" edgeTrim="true" name="Outermost bounding edge">
<PntList3D>1.5181307542E7 2125297.27 1713.976 1.5181309121E7 2125348.661 1713.65 1.518131357E7 2125401.188 1713.624 1.5181355394E7 2125953.634 1712.622 1.5181471897E7 2127035.359 1711.076 1.5181474238E7 2127060.368 1711.571 1.5181479644E7 2127074.35 1711.4 1.5181484532E7 2127081.58 1711.23 1.5181486144E7 2127083.79 1711.24 1.5181526576E7 2127114.416 1710.763 1.5181604217E7 2127162.511 1710.742 1.518173257E7 2127220.112 1712.713 1.5182046629E7 2127316.035 1716.328 1.5182350908E7 2127362.323 1709.085 1.518238492E7 2126720.863 1678.373 1.5182383044E7 2126559.786 1663.524 1.518236883E7 2126031.128 1708.884 1.5182353785E7 2125775.21 1680.648 1.5182361822E7 2125348.267 1648.468 1.518235892E7 2125223.263 1646.325 1.518233926E7 2124751.224 1640.587 1.5181441405E7 2125081.466 1700.044 1.518132618E7 2125144.398 1708.546 1.5181317827E7 2125194.92 1712.947 1.5181309366E7 2125246.027 1714.161</PntList3D>
</Boundary>
</Boundaries>
</SourceData>
<Definition surfType="TIN">
<Pnts>
</Pnts>
<Faces>
</Faces>
</Definition>
<Project desc="GPS Survey, UTM14 North, Autonomous Base, Geoid 2009, Reedy
</Project>
<Application manufacturer="USDA NRCS" name="Engineering Field Tools" version="3.4.1.2">
<Author createdBy="james.reedy"/>
</Application>
</LandXML>
So far I have come up with this code:
Dim doc As XmlDocument = New XmlDocument()
doc.Load(Xml_in)
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("", "http://ift.tt/1CjiOKC")
Dim nodelist As XmlNodeList = doc.SelectNodes("//LandXML", nsmgr)
Dim nodelist1 As XmlNode = doc.SelectSingleNode("//LandXML")
For i As Integer = 0 To nodelist.Count - 1
If (nodelist(i).HasChildNodes) Then
Dim nodes As XmlNodeList = nodelist(i).ChildNodes
For j As Integer = nodelist(i).ChildNodes.Count - 1 To 0 Step -1
If (nodes(j).Name = "Units") Then
msgbox("Found Units")
Dim xn As XmlNode = nodes(j)
nodelist(i).RemoveChild(nodes(j))
nodelist1.InsertBefore(xn, nodelist1.FirstChild)
End If
Next
End If
Next
doc.Save(Xml_out)
MsgBox("Done")
However it will only output the original file and never displays the first message box. I think its not finding Units and I cant figure out how to get it to. Any help will be appreciated!
No comments:
Post a Comment