public override string GetAttribute(string localName, string namespaceURI) { if (null == localName) { throw new ArgumentNullException("localName"); } // reader allows calling GetAttribute, even when positioned inside attributes XPathNavigator nav = _nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (!nav.MoveToParent()) { return(null); } break; default: return(null); } // are they really looking for a namespace-decl? if (namespaceURI == XmlConst.ReservedNsXmlNs) { if (localName == "xmlns") { localName = string.Empty; } return(nav.GetNamespace(localName)); } if (null == namespaceURI) { namespaceURI = string.Empty; } // We need to clone the navigator and move the clone to the attribute to see whether the attribute exists, // because XPathNavigator.GetAttribute return string.Empty for both when the the attribute is not there or when // it has an empty value. XmlReader.GetAttribute must return null if the attribute does not exist. if ((object)nav == (object)_nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(localName, namespaceURI)) { return(nav.Value); } else { return(null); } }
public override string GetAttribute(string localName, string namespaceURI) { if (localName == null) { throw new ArgumentNullException("localName"); } XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (nav.MoveToParent()) { break; } return(null); default: return(null); } if (namespaceURI == "http://www.w3.org/2000/xmlns/") { if (localName == "xmlns") { localName = string.Empty; } return(nav.GetNamespace(localName)); } if (namespaceURI == null) { namespaceURI = string.Empty; } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(localName, namespaceURI)) { return(nav.Value); } return(null); }
public override string GetAttribute(string name) { // reader allows calling GetAttribute, even when positioned inside attributes XPathNavigator nav = _nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (!nav.MoveToParent()) { return(null); } break; default: return(null); } string prefix, localname; ValidateNames.SplitQName(name, out prefix, out localname); if (0 == prefix.Length) { if (localname == "xmlns") { return(nav.GetNamespace(string.Empty)); } if ((object)nav == (object)_nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(localname, string.Empty)) { return(nav.Value); } } else { if (prefix == "xmlns") { return(nav.GetNamespace(localname)); } if ((object)nav == (object)_nav) { nav = nav.Clone(); } if (nav.MoveToFirstAttribute()) { do { if (nav.LocalName == localname && nav.Prefix == prefix) { return(nav.Value); } } while (nav.MoveToNextAttribute()); } } return(null); }
public XmlQualifiedName GetXmlType(XPathNavigator source) { var qualifiedType = source.GetAttribute("type", Xsi); if (string.IsNullOrEmpty(qualifiedType) == false) { string name, namespaceUri = null; var prefix = SplitQualifiedName(qualifiedType, out name); if (prefix != null) namespaceUri = source.GetNamespace(prefix); return new XmlQualifiedName(name, namespaceUri); } return null; }
public string CreateNamespace(string prefix, string namespaceUri, XPathNavigator source) { if (string.IsNullOrEmpty(namespaceUri) == false) { source = source.Clone(); source.MoveToRoot(); source.MoveToChild(XPathNodeType.Element); if (string.IsNullOrEmpty(prefix)) prefix = AddNamespace(namespaceUri); var existing = source.GetNamespace(prefix); if (existing == namespaceUri) return prefix; if (string.IsNullOrEmpty(existing) == false) return null; source.CreateAttribute("xmlns", prefix, "", namespaceUri); } return prefix; }
public override string GetAttribute( string localName, string namespaceURI ) { if ( null == localName ) throw new ArgumentNullException("localName"); // reader allows calling GetAttribute, even when positioned inside attributes XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (!nav.MoveToParent()) return null; break; default: return null; } // are they really looking for a namespace-decl? if( namespaceURI == XmlReservedNs.NsXmlNs ) { if (localName == "xmlns") localName = string.Empty; return nav.GetNamespace( localName ); } if ( null == namespaceURI ) namespaceURI = string.Empty; // We need to clone the navigator and move the clone to the attribute to see whether the attribute exists, // because XPathNavigator.GetAttribute return string.Empty for both when the the attribute is not there or when // it has an empty value. XmlReader.GetAttribute must return null if the attribute does not exist. if ((object)nav == (object)this.nav) nav = nav.Clone(); if ( nav.MoveToAttribute( localName, namespaceURI ) ) { return nav.Value; } else { return null; } }
public override string GetAttribute( string name ) { // reader allows calling GetAttribute, even when positioned inside attributes XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (!nav.MoveToParent()) return null; break; default: return null; } string prefix, localname; ValidateNames.SplitQName( name, out prefix, out localname ); if ( 0 == prefix.Length ) { if( localname == "xmlns" ) return nav.GetNamespace( string.Empty ); if ( (object)nav == (object)this.nav ) nav = nav.Clone(); if ( nav.MoveToAttribute( localname, string.Empty ) ) return nav.Value; } else { if( prefix == "xmlns" ) return nav.GetNamespace( localname ); if ((object)nav == (object)this.nav) nav = nav.Clone(); if (nav.MoveToFirstAttribute()) { do { if (nav.LocalName == localname && nav.Prefix == prefix) return nav.Value; } while (nav.MoveToNextAttribute()); } } return null; }
private void GetNamespaceConsistentTree (XPathNavigator nav) { nav.MoveToFirstChild (); nav.MoveToFirstChild (); nav.MoveToNext (); Assert.AreEqual ("ns1", nav.GetNamespace (""), "#1." + nav.GetType ()); nav.MoveToNext (); nav.MoveToNext (); Assert.AreEqual ("", nav.GetNamespace (""), "#2." + nav.GetType ()); }
private QName [] ParseMappedPrefixes (string list, XPathNavigator nav) { if (list == null) return null; ArrayList al = new ArrayList (); foreach (string entry in list.Split (XmlChar.WhitespaceChars)) { if (entry.Length == 0) continue; if (entry == "#default") al.Add (new QName (String.Empty, String.Empty)); else { string entryNS = nav.GetNamespace (entry); if (entryNS != String.Empty) al.Add (new QName (entry, entryNS)); } } return (QName []) al.ToArray (typeof (QName)); }
public static bool TryParseDataTypeReference(string typeStr, XPathNavigator dataTypeElementNav, out string schemaURI, out string dataTypeName) { schemaURI = null; dataTypeName = null; int index = typeStr.LastIndexOf(':'); if (index == -1) return false; string prefix = typeStr.Substring(0, index); dataTypeName = typeStr.Substring(index + 1); schemaURI = prefix.StartsWith("urn:") ? prefix : dataTypeElementNav.GetNamespace(prefix); return true; }
public static QName FromString (string name, XPathNavigator current, bool useDefaultXmlns) { if (current.NodeType == XPathNodeType.Attribute) (current = current.Clone ()).MoveToParent (); int colon = name.IndexOf (':'); if (colon > 0) return new QName (name.Substring (colon+ 1), current.GetNamespace (name.Substring (0, colon))); else if (colon < 0) return new QName (name, useDefaultXmlns ? current.GetNamespace (String.Empty) : ""); else throw new ArgumentException ("Invalid name: " + name); }
public override string GetAttribute(string name) { string str; string str2; XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (nav.MoveToParent()) { break; } return(null); default: return(null); } ValidateNames.SplitQName(name, out str, out str2); if (str.Length == 0) { if (str2 == "xmlns") { return(nav.GetNamespace(string.Empty)); } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(str2, string.Empty)) { return(nav.Value); } } else { if (str == "xmlns") { return(nav.GetNamespace(str2)); } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToFirstAttribute()) { do { if ((nav.LocalName == str2) && (nav.Prefix == str)) { return(nav.Value); } }while (nav.MoveToNextAttribute()); } } return(null); }
public override string GetAttribute(string localName, string namespaceURI) { if (localName == null) { throw new ArgumentNullException("localName"); } XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (nav.MoveToParent()) { break; } return null; default: return null; } if (namespaceURI == "http://www.w3.org/2000/xmlns/") { if (localName == "xmlns") { localName = string.Empty; } return nav.GetNamespace(localName); } if (namespaceURI == null) { namespaceURI = string.Empty; } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(localName, namespaceURI)) { return nav.Value; } return null; }
public override string GetAttribute(string name) { string str; string str2; XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (nav.MoveToParent()) { break; } return null; default: return null; } ValidateNames.SplitQName(name, out str, out str2); if (str.Length == 0) { if (str2 == "xmlns") { return nav.GetNamespace(string.Empty); } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(str2, string.Empty)) { return nav.Value; } } else { if (str == "xmlns") { return nav.GetNamespace(str2); } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToFirstAttribute()) { do { if ((nav.LocalName == str2) && (nav.Prefix == str)) { return nav.Value; } } while (nav.MoveToNextAttribute()); } } return null; }
public MeshElement Parse(XPathNavigator nav, string geomName, bool generateTangents = false) { Name = geomName; nsName = nav.GetNamespace("c"); var mesh = nav.SelectSingleNode("c:mesh", nsManager); if (mesh == null) throw new GeometryParserException("Geometry does not contain mesh!"); ParseMesh(mesh); CreateArrays(generateTangents); MeshElement retMesh = new MeshElement(_vertexDeclaration, vertexData, indexData); return retMesh; }
private void ParseSource(XPathNavigator nav) { string sourceName = nav.GetAttribute("id", nav.GetNamespace("c")); Console.WriteLine("found source: " + sourceName); var arrayNode = nav.SelectSingleNode("c:float_array", nsManager); int arrayCount; if (!int.TryParse(arrayNode.GetAttribute("count", arrayNode.GetNamespace("c")), out arrayCount)) throw new GeometryParserException("could not parse source: " + sourceName + " array"); sources.Add(sourceName, new Source(new float[arrayCount])); string[] parts = arrayNode.InnerXml.Split(' '); for (int i = 0; i < arrayCount; ++i) { float fVal; if (!float.TryParse(parts[i], out fVal)) throw new GeometryParserException("could not parse source: " + sourceName + " array, element: " + i); sources[sourceName][i] = fVal; } var accessorNode = nav.SelectSingleNode("c:technique_common/c:accessor", nsManager); int.TryParse(accessorNode.GetAttribute("stride", nsName), out sources[sourceName].stride); }